0

I am trying to make a custom stream class because for some reason standard string objects crash my program when i try to output them, i believe i know why now. When i tried to overload the << operator for a string object by making it a friend of my class, whenever i try to return it the os i get this error:

main.cpp|71|Error E2125 : Compiler could not generate copy constructor for class 'ostream' in function operator <<(ostream &,const u_string &)|
||=== Build finished: 1 errors, 0 warnings ===|


this is what the sample of my code looks like:

std::ostream operator<<(std::ostream& os, const u_string& uStr) {
os<<uStr.str;
return os;

}

this is the definition of this prototype defined in my class:

friend std::ostream operator<<(std::ostream& os, const u_string& uStr);

I would like it if someone could tell me how do fix this or atleast what might be causing this so i can figure out a solution. Thanks

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by code zombie
0

Apparently you want to return a reference, like so

friend std::ostream & operator<<(std::ostream& os, const u_string& uStr);
// and
std::ostream & operator<<(std::ostream& os, const u_string& uStr) {
os<<uStr.str;
return os;
}
0

Apparently you want to return a reference, like so

friend std::ostream & operator<<(std::ostream& os, const u_string& uStr);
// and
std::ostream & operator<<(std::ostream& os, const u_string& uStr) {
os<<uStr.str;
return os;
}

wow thanks a ton i can't believe it was that simple.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.