I am currently trying to overload the '<<' operator using a struct that holds a flight's number, origin, destination, and price. However, I am continuously getting this error. I have searched boards and tried multiple of the suggestions but I have had no luck. Any help is well appreciated!
My error is:
"error: expected unqualified-id before 'friend'"
Here's my header file:
Code:
#include <iostream>#include <string>
using namespace std;
#ifndef TYPE_H
#define TYPE_H
struct flightStruct
{
int flightNum; //Flight Number
string source; //Origin Flight
string destination; //Destination Flight
int price; //Price of Flight
bool operator < (const flightStruct& rhs) const; //Overloaded operator for "less than"
bool operator == (const flightStruct& rhs) const; //Overloaded operator for "equal to"
bool operator != (const flightStruct& rhs) const; //OVerloaded operator for "not equal to"
friend ostream& operator << (ostream& os, const flightStruct& rhs); //Overloaded operator for output
};
flightStruct flightRec; //flightRec is variable to represent flightStruct
#endif
And my overloaded '<<' definition:
Code:
friend flightStruct::ostream& operator << (ostream& os, const flightStruct& rhs) //Overloaded operator for '<<'{ //for struct output
os << rhs.flightStruct.flightNum
<< rhs.flightStruct.source
<< rhs.flightStruct.destination
<< rhs.flightStruct.price;
return os;
}