I'm attempting to teach myself C++ and up till now its been fairly easy. I'm having tons of issues understanding overloading operators and specifically overloading >> and <<. I've been going to many sites trying to figure this out and even am using some sample code to try to give myself greater understanding. This is what I have so far in code.
In class Rectangle:
I believe this should be done in main, but can’t see where they are doing it.Code:friend istream& operator>>(istream& inputStream, Rectangle& Rect);
I keep getting a compile error on lineCode:istream& operator>>(istream& inputStream, TRectangle& R) { cout << "Length: "; inputStream >> R.Length; cout << "Height: "; inputStream >> R.Height; return inputStream; }
saying that I need a ';' before { but none of the syntax i've found anywhere has this ;. If I remove this bit of code, I no longer get the compile error so it has to be here.Code:istream& operator>>(istream& inputStream, TRectangle& R)
Any help with understanding overloading >> and << would be greatly appreciated.



LinkBack URL
About LinkBacks


