R
Rene Ivon Shamberger
I have the class below that overloads the extractor operator, however, Visual Studio 10 complains giving me an error. I know why the error is created, I think, but I don't know how to solve it.
The problem is that the operator<< method is inside a namespace (ABC), I think that that is the problem.
How can I solve this issue? or, am I looking at the wrong thing here?
#include <iostream>
namespace ABC{
class SomeClass{
std::string str;
public:
SomeClass() { str = "Text";}
virtual ~SomeClass();
std::string& getData(){return str;}
friend std:stream& operator<<( std:stream& os,
ABC::SomeClass obj );
}; // class
} //namespace
std:stream& operator<<( std:stream& os, ABC::SomeClass obj ) {
return os << obj.getData() << std::endl;
}
1>main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
*** HERE IS THE PROBLEM ***
ABC:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,
class ABC::SomeClass)" (??6jme@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@VAddress@0@@Z)
referenced in function "void __cdecl testAddress(void)" (?testAddress@@YAXXZ)
The problem is that the operator<< method is inside a namespace (ABC), I think that that is the problem.
How can I solve this issue? or, am I looking at the wrong thing here?
#include <iostream>
namespace ABC{
class SomeClass{
std::string str;
public:
SomeClass() { str = "Text";}
virtual ~SomeClass();
std::string& getData(){return str;}
friend std:stream& operator<<( std:stream& os,
ABC::SomeClass obj );
}; // class
} //namespace
std:stream& operator<<( std:stream& os, ABC::SomeClass obj ) {
return os << obj.getData() << std::endl;
}
1>main.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl
*** HERE IS THE PROBLEM ***
ABC:perator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,
class ABC::SomeClass)" (??6jme@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV12@VAddress@0@@Z)
referenced in function "void __cdecl testAddress(void)" (?testAddress@@YAXXZ)