I tried to overload operator <
for sorting the rooms based on price.
Here is the relevant part of my code:
class Room{
protected:
int roomNo;
int category;
Client client;
public:
Room();
Room(int no, int cat, Client cl);
void printData();
int charge();
Room operator < (Room &r1);
};
Room Room::operator < (Room &r1){
if(this->charge() < r1.charge()){
return r1;
}
else{
return *this;
}
}
But the compiler gives me the following error when I try to use operator<
:
main.cpp:(.text+0x2d8): undefined reference to `Room::operator<(Room const&)'
main.cpp:(.text+0x2ff): undefined reference to `Room::operator<(Room const&)'
[Error] ld returned 1 exit status
Makefile.win recipe for target 'Ask01.exe' failed
Why doesn't the code compile?