C++ Overloading stream-extraction operator - HELP!

  • Thread starter Thread starter yeutim
  • Start date Start date
Y

yeutim

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]
 
yeutim said:
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!

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

Try

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

-cd
 
Back
Top