Question

Could someone please tell me what is wrong with this overload for the << operator. Visual studio tells me that I have to many parameters. Node is a structure if that helps.

ostream& operator << (ostream& strm, const node* &obj )
{
    strm << "ItdID: " << obj.itemId << "\nItem Description: " << obj.itemDescription << "\nItem Quanity: " << obj.quanity 
         << "\nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "\nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
    return strm;
}
Was it helpful?

Solution

You need to declare ostream& operator << (ostream& strm, const node* &obj ) as a friend function to your node class.

So inside your node class you will have

friend ostream& operator << (ostream& strm, const node* &obj );

and then in your cpp file you will have

ostream& operator << (ostream& strm, const node* &obj )
{
    strm << "ItdID: " << obj.itemId << "\nItem Description: " << obj.itemDescription << "\nItem Quanity: " << obj.quanity 
         << "\nWholesale Cost: $" << fixed << showpoint << setprecision(2) << obj.wholesale << "\nRetail Cost: $" << fixed << showpoint << setprecision(2) << obj.retail;
    return strm;
}

This should fix your bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top