Overloading ostream -


i have class example test in test.h have

friend ostream& operator<< (ostream& out, const test& outstr);

in test.cc

ostream& operator <<(ostream& out, test& strout) { out<< "test"; return out; }

in main test x; cout<< x;

i recieve error message: error: undefined reference `operator<<(std::basic_ostream >&, test const&)

whats problem?

you have const in declaration:

friend ostream& operator<< (ostream& out, const test& outstr);

and no const in implementation:

ostream& operator <<(ostream& out, missing const test& strout)

adding const implementation should solve issue.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -