I'm trying to overloading the operator << in c++. here is my code:
both toString and the overloading of << are inside the .cpp file of VipCustomer
string VipCustomer::toString(){
return "VIP Name: " + this->m_cuName + " Bill: "
+ to_string(this->m_cuCurrentBiil);
}
ostream& operator<< (ostream& out, VipCustomer *obj){
return out << obj->toString();
}
int main(){
VipCustomer * cus2 = new VipCustomer("bob", 10);
cout << cus2 << endl;
}
The output that i'm getting is the address of cus2, what did i do wrong ?
Regarding to @T.C comments changed it to:
int main (){
VipCustomer cus2("bob", 10);
cout << &cus2;
}
Inside the cpp file:
string VipCustomer::toString(){
return "VIP Name: " + this->m_cuName + " Bill: " + to_string(this->m_cuCurrentBiil);
}
ostream& operator<< (ostream& out, VipCustomer &obj){
return out << obj.toString();
}
inside the .h file :
class VipCustomer :public Customer
{
public:
VipCustomer();
VipCustomer(std::string name ,int bill);
~VipCustomer();
void addtoBill(int amount);
string toString();
};
Still the same problem.