overloaded on overloads

This is a discussion on overloaded on overloads within the C++ Programming forums, part of the General Programming Boards category; Hi everyone help!) Assuming I have a class Seat that has both a char Lastname[20]; and int seatIDNum; I am ...

  1. #1
    emceedee
    Guest

    Unhappy overloaded on overloads

    Hi everyonehelp!)
    Assuming I have a class Seat that has both a
    char Lastname[20];
    and int seatIDNum;

    I am overloading both the > & < operators to ease my sort by LastName (alpha) and by seat ID Num...(sort BACK from alpha to
    ascending order 1-->12).
    the functions are memberfunctions of class Seat so I can use the this pointer as the first parameter and compare the second seat's
    data members to the this
    here are the member function:
    Code:
    // Overloaded greater than operator
    bool Seat::operator >( const Seat &seatB ) const
     { 
      
      if  ( (this->LastName) > (seatB.LastName))
       { return true; }
      else 
       { return false; }
      
     } // end function operator >
    
    // Overloaded less than operator
    bool Seat::operator <( const Seat *seatB ) const
     { 
      
      if  ((this->iSeatNum, seatB->iSeatNum))
       { return true; }
      else 
       { return false; }
      
     } // end function operator <
    and my attempt to use them in my alpha function (also a data member, but of another class that has a private instance of an array of dynamically allocated Seats (seats).

    Code:
     
    //alphabetize:client function
    void Airplane::alpha ()
    //in: *s[], Mnum; out:none
    { 
     
     
     Seat *tempname;
     for (int i = 0; i < MAX_ITEMS; i++)
     {
      for (int j = i+1; j < MAX_ITEMS; j++)
      {
       
       //use of overloaded > operator 
    
       if ((seats[i] > seats[j]))  //this does not work 
       {
        tempname = seats[i];
        seats[i] = seats[j];
        seats[j] = tempname;
        
       }//if 
      }//for
     }//
     
     printalpha();
     
     //======switch back===========
     
     for (i = 1; i < MAX_ITEMS; i++)
     {
      
      for (int j = 0; j < MAX_ITEMS; j++)
      {
    
       //use of overloaded < operator  // i used an overloaded < to switch to ascending seat num... //this works! 
    
    
       if (seats[j] < seats[i]) 
       {
        tempname = seats[i];
        seats[i] = seats[j];
        seats[j] = tempname;
        
       }//if  
      }//for
     }//for  
    }//Fx
    my question: why is the > overloader OR the alpha function NOT
    working to alphabetize by lastname? when i call the > in the beginning part of alpha the seats are arranged in descending order by seatIDnum!... I have tried this every which way and inside out..(my function works fine if I use pointers to getLastname instead of the overloaded opertor) so it's not the logic, it's that even using LastName in the bool it is somehow only seeing the ints (seatIDnum) wierd? or am I missing something.
    thx alot
    M

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,670
    You are comparing pointers and not class instances.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-09-2008, 10:19 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 10:53 PM
  5. Cannot resolve overloaded function
    By Mithoric in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2003, 02:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21