Argument-Dependent Lookup

Discussion in 'C++' started by siddhu, May 14, 2007.

  1. siddhu

    siddhu Guest

    Dear experts,

    As far as I understood the ADL concept things shoul work in the
    followin way.

    I have a global ostream operator defined as

    //ostreamtest.cpp
    #include<iostream>
    using namespace std;

    ostream& operator<<(ostream& out,const string& str)
    {
    out<<"in ostream"<<endl;
    out<<str.c_str()<<endl;

    return out;
    }

    int main()
    {

    }
    siddhu, May 14, 2007
    #1
    1. Advertising

  2. siddhu

    Old Wolf Guest

    On May 15, 7:40 am, siddhu <> wrote:
    > As far as I understood the ADL concept things shoul work in the
    > followin way.
    >
    > ostream& operator<<(ostream& out,const string& str)
    > {
    > out<<"in ostream"<<endl;
    > out<<str.c_str()<<endl;
    >
    > return out;
    > }


    This function will never be found for an expression like:
    foo << bar;

    because of ADL ! The arguments are all in namespace std,
    so the compiler only searches namespace std. It doesn't
    find your function that's in the global namespace.

    Note that there is nothing you can do about this; trying
    to add your function to namespace std would cause
    undefined behaviour.
    Old Wolf, May 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Martin Vorbrodt

    argument dependent lookup

    Martin Vorbrodt, Oct 25, 2005, in forum: C++
    Replies:
    13
    Views:
    507
    Default User
    Oct 25, 2005
  2. siddhu

    Argument-Dependent Lookup

    siddhu, May 14, 2007, in forum: C++
    Replies:
    4
    Views:
    471
    James Kanze
    May 15, 2007
  3. Belebele
    Replies:
    6
    Views:
    424
    Belebele
    Dec 11, 2007
  4. Replies:
    2
    Views:
    432
    Balog Pal
    Apr 9, 2009
  5. neverhoodboy
    Replies:
    1
    Views:
    439
    Johannes Schaub
    Mar 4, 2012
Loading...

Share This Page