I've some problem with get me weired. I've typedef'ed a std::vector which contains some own class:
typedef std::vector<data::WayPoint> TWayPointList; This is a nested type inside the structure DataHandler which resists in some namespace data.
So, now I want to print out the single contents of the vector. For this, my idea was to overload the << operator and loop through the single elements of typedef'ed vector. So I declared the following output operator inside the structure DataHandler:
namespace data { structure DataHandler { // ... some code typedef std::vector<data::WayPoint> TWayPointList; // ... some more code /** * @brief Globally overloaded output operator * * @param[in] arOutputStream Reference to output stream. * @param[in] arWayPointList WayPoint which should be printed to output stream. */ LIB_EXPORTS friend std::ostream& operator<<(std::ostream& arOutputStream, const data::DataHandler::TWayPointList& arWayPointList); } // structure DataHandler } // namespace data and defined it in the respective source file:
namespace data { std::ostream& operator<<(std::ostream& arOutputStream, const DataHandler::TWayPointList& arWayPointList) { for(DataHandler::TWayPointList::const_iterator lIterator = arWayPointList.begin(); lIterator < arWayPointList.end(); ++lIterator) { arOutputStream << *lIterator << std::endl; } return arOutputStream; } } // namespace data This compiles fine. But if I add something like this
int main(int argc, char *argv[]) { // create Waypoint data::WayPoint lWayPoint; // create waypoint list data::DataHandler::TWayPointList lWayPointList; // append two elements lWayPointList.push_back(lWayPoint); lWayPointList.push_back(lWayPoint); std::cout << lWayPointList << std::endl; return 0; } in my testmain.cpp, the compiler mentions, that it couldn't find the correct operator<< (and make a lot of assumptions, which one it has found...including some of my own defined in other classes). Some error like this
src/main.cpp:107: error: no match for 'operator<<' in 'std::cout << lWayPointList' src/main.cpp:107:18: note: candidates are: ... a long list of canditates... I think it has something to do with ADL, but I didn't get the point.
So, any ideas and adivce to get the code work?
[edit] I've added a few files to the source code and the error output for clarifying.
dataandmkilib?<<(ostream&, const WayPoint&)defined?datais a namespace then youroperator<<definition must go inside of said namespace.