Quantcast

Jump to content


Photo

C++ overloading operators


  • Please log in to reply
2 replies to this topic

#1 Melchoire

Melchoire
  • 5284 posts


Users Awards

Posted 24 November 2009 - 07:10 PM

So in a class called "Rectangle" this is one of the public members. This is what it's prototype looks like:
friend ostream& operator<< (ostream& os, const Rectangle& myRectangle);
and in a .cpp file somewhere I have this is as the function definition:
ostream& operator<<(ostream& os, const Rectangle& myRectangle)
{
	os << "Width: " << setw(20) << myRectangle.GetWidth << endl;
	os << "Height: " << setw(20) << myRectangle.GetHeight << endl;
	os << "Area: " << setw(20) << myRectangle.GetArea << endl;
	os << "X: " << setw(20) << myRectangle.GetXLocation << endl;
	os << "Y: " << setw(20) << myRectangle.GetYLocation << endl;
	os << "Rectangles Created: " << setw(20) << myRectangle.GetRectanglesCreated << endl;
	os << "Rectangles Existing: " << setw(20) << myRectangle.GetRectanglesExisting << endl;
	os << "Color: " <<  setw(20) << "R:" << myRectangle.GetBlockColour.redNumber << " G:" << myRectangle.GetBlockColour.greenNumber << " B:" << myRectangle.GetBlockColour.blueNumber << " A:" << myRectangle.GetBlockColour.alphaNumber << endl;
}
I must be doing something wrong because for every accessor I'm getting an error that reads:

function call missing argument list; use '&Rectangle::(accessor name)' to create a pointer to member



What am I doing wrong?

#2 travis

travis
  • 5408 posts


Users Awards

Posted 24 November 2009 - 08:31 PM

Ohm's law.
kk

#3 Andy

Andy
  • 226 posts

Posted 26 November 2009 - 02:20 AM

tbh, I don't know if this will work, but try changing the & in the arguments to * ;)


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users