Colossusx10
n00b
- Joined
- May 19, 2007
- Messages
- 8
I am trying to overload the << operator, and use it to print out a list.
For some reason, it isn't working out.
Here's my class deifnition:
The function:
When I compile I get these messages:
error C2440: 'initializing' : cannot convert from 'JGAirlines::AirNode *' to 'JGAirlines *'
error C2039: 'next' : is not a member of 'JGAirlines'
error C2039: 'person' : is not a member of 'JGAirlines'
I tried using:
Instead of:
but it still doesn't work.
Can anyone tell me what I'm doing wrong?
For some reason, it isn't working out.
Here's my class deifnition:
Code:
class JGAirlines
{
friend ostream &operator<<(ostream &,JGAirlines &);
public:
JGAirlines(int,int); // Constructor
~JGAirlines(); // Destructor
void RegisterPassenger(); // Enters a passenger name.
void RegisterPassenger(string);
void Delete(); //Deletes a passenger from the flight roster.
void PrintFlightManifest();
bool FindPassenger(string); //Finds a passenger on a flight.
void Together(); //Registers passengers flying together.
void Merge(); //Merges two flights.
void Seat(); //Assigns seat numbers to all passengers.
void ReadFile(); //Reads a set of passengers from a file.
private:
struct AirNode // node that represents passenger record
{
string person; // passenger's name
AirNode *next; // pointer to the next passenger record
};
int flightID; // unique ID of the flight
int maxSize; // maximum capacity of the flight
int size; // number of passengers on board
AirNode *head; // head of the linked list of passengers in alphabetical order
};
#endif
};
#endif
The function:
Code:
ostream &operator<<(ostream &output, JGAirlines &getPassenger)
{
for(JGAirlines *current = getPassenger.head; current != NULL; current = current->next)
{
output << current->person <<endl;
}
return output;
}
When I compile I get these messages:
error C2440: 'initializing' : cannot convert from 'JGAirlines::AirNode *' to 'JGAirlines *'
error C2039: 'next' : is not a member of 'JGAirlines'
error C2039: 'person' : is not a member of 'JGAirlines'
I tried using:
Code:
friend ostream &operator<<(ostream &,AirNode&);
Instead of:
Code:
friend ostream &operator<<(ostream &,JGAirlines &);
but it still doesn't work.
Can anyone tell me what I'm doing wrong?