Apr 10, 2009 at 3:46am
I have the following code, I need to display a message on screen, using a function on a class:
Class A
.
.
void getname1()
{
cout<<getname();
}
void getpoints1()
{
cout<<getpoints();
}
void printData()
{
cout<<"Player:";
getname1();
cout<<", score:";
getpoints1();
cout<<", ";
}
.
.
.int main()
{
.
.
.
cout<<"The winner is "<<winner.printData()<<endl;
I am getting error:error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
Any idea?I am not allowed to change main
Apr 10, 2009 at 12:15pm
If you can not change the call in main() then you will have to change the return type of printData(). Build a string and return that.
Apr 10, 2009 at 7:54pm
Still, I have a string and some variables to return in the same line
Apr 10, 2009 at 8:33pm
You can use a stringstream to build the string
Apr 11, 2009 at 4:52pm
why don't you replace 'cout' with a stringstream and then return the contents of that stream?