Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

C++ Overloading stream-extraction operator - HELP!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yeutim - 18 Feb 2005 21:53 GMT
I can't find anything wrong this with this class. Especially,
Overloading Stream-Extraction Operator (in blue). Any one know what
do I need to fix this problem please reply. Thank you for your help!

---------------------------------------------

class MyData{
public:
int x;
float y;
bool operator==(MyData);
MyData operator=(MyData);

friend ostream &operator<<(ostream
&output, const MyData &obj);

};

bool MyData::operator==(MyData obj)
{
if(x==obj.x && y==obj.y)
return true;
else
return false;
}

MyData MyData::operator=(MyData obj)
{
x = obj.x;
y = obj.y;
return *this;
}

[color=blue:173fdd256e]ostream MyData::&operator<<(ostream
&output, const MyData &obj)
{
out<<"integer: "<<obj.x<<"  float: "<<obj.y;
return output;
}
[/color:173fdd256e]
Carl Daniel [VC++ MVP] - 18 Feb 2005 22:15 GMT
> I can't find anything wrong this with this class. Especially,
> Overloading Stream-Extraction Operator (in blue). Any one know what
[quoted text clipped - 6 lines]
> return output;
> }

Try

ostream& MyData::operator<<(
   ostream& out,
   const MyData& obj
)
{
 out<<"integer: "<<obj.x<<"  float: "<<obj.y;
 return output;
}

-cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.