Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8649163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:29:31+00:00 2026-06-12T13:29:31+00:00

I’ve some problem with get me weired. I’ve typedef’ed a std::vector which contains some

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:29:32+00:00Added an answer on June 12, 2026 at 1:29 pm

    The friend declaration declares a function at namespace level in the namespace of the class that has such friend declaration. From the definition of the operator it seems that you are defining it in the global namespace (incidentally what your comment in the friend declaration says, too bad compilers don’t read comments). You need to define the operator<< in the correct namespace:

    std::ostream& mkilib::operator<<(std::ostream& arOutputStream,
                /*^^^^^^^^*/         const mkilib::DataHandler::TWayPointList& arWayPointList)
    

    or alternatively:

    namespace mkilib {
        std::ostream& operator<<(std::ostream& arOutputStream,
                                 const DataHandler::TWayPointList& arWayPointList) {...}
    }
    

    In your program there were two operator<< declared that took the TWayPointList object, one in the global namespace (the definition is a self declaration) and the one in the ::mkilib namespace (from the friend declaration). Argument dependent lookup was finding the one in ::mkilib, but that was never defined in code.


    After the update it seems that this is not really the issue, as the compiler is not able to find the overload (the answer above was about code that compiled but not linked). There is something that you have changed from your code to what you ask regarding the namespaces. If Waypoint and the operator<< that takes the std::vector<Waypoint> are defined in the same namespace, then ADL will find the correct overload. Note that the namespace where DataHandler is defined does not have any effect.


    Actually now that I think about it, the original answer does apply. The friend declaration does not have any effect on lookup as ADL won’t look inside DataHandler searching for that operator, so the only declaration of operator<< is the self-declaration in the definition.

    Note that a friend declaration declares an entity at namespace level, but the declaration is only visible inside the class that has the friend declaration.

    Piece of advice: Avoid using directives, they only bring confusion and pain. If needed, reopen the namespace or qualify identifiers… using directives make reasoning about lookup much more complex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.