Thread: comparison problems...

  1. #1
    Registered User
    Join Date
    Jan 2002

    Question comparison problems...


    I am trying to do a comparison between a variable passed into a function and a pointer. The function is within a class that I set up called SortedType:

    class SortedType
    SortedType(); // default constructor
    SortedType(int); // regular constructor
    void MakeEmpty(); // set list to empty
    bool IsEmpty(); // test for an empty list (true if empty)
    bool IsFull(); // test for a full list (true if full)
    bool RetrieveItem (student&); // retrieve an item matching the key field
    bool InsertItem(student); // add item to the list in order by key field
    bool DeleteItem (student); // delete an item matching the key field
    void ResetList(); // set next pointer to beginning of list
    bool GetNextItem(student&); // get next sequential item
    int length; // number of items in list plus subscript of next add
    int currentPos; // item to retrieve on Get Next Item function
    int maxItems; // from user constructor for size of array
    int location; // location of student* info
    bool moreToSearch; // returns true if greater or false if less
    student* info; // pointer to the student array

    the function is called InsertItem:

    bool SortedType::InsertItem(student item)
    if (length >= maxItems)
    return false;

    location = 0;
    moreToSearch = (location < length);

    while (moreToSearch)
    if (item < info[location])
    moreToSearch = false;
    moreToSearch = (location < length);

    for (int index = length; index > location; index--)
    info[index] = info[index - 1];

    info[location] = item;
    return true;

    Basically, it does not like this statement:
    if (item < info[location]) and gives me this error message: "no match for 'student& < student&'".

    What is wrong with this statement?

    Thank you!


  2. #2
    Join Date
    Jan 2002
    Looks like you have to write your own comparison fn for 'student'
    by defining fns for the comparison operators ie there is no default comparison for 'student' types.

  3. #3
    Registered User
    Join Date
    Jan 2002

    Thumbs up Thanks!

    Thanks Ken!

    I thought about it and put in a ".Key" notation for comparing the key fields and it worked. I thought originally it would go character by character and do the comparison.

    Thanks for your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Common Problems
    By WolfPack in forum C Programming
    Replies: 4
    Last Post: 01-28-2003, 06:38 PM
  3. tile colliision detection problems
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 10-23-2002, 09:26 PM
  4. Problems with my RPG app
    By valar_king in forum Game Programming
    Replies: 1
    Last Post: 12-15-2001, 08:07 PM
  5. problems with too many warning messages?
    By Isometric in forum C Programming
    Replies: 9
    Last Post: 11-25-2001, 01:23 AM