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
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.
Still, I have a string and some variables to return in the same line
You can use a stringstream to build the string
why don't you replace 'cout' with a stringstream and then return the contents of that stream?