Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Argument-Dependent Lookup (http://www.velocityreviews.com/forums/t506492-argument-dependent-lookup.html)

siddhu 05-14-2007 07:40 PM

Argument-Dependent Lookup
 
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()
{

}


Old Wolf 05-14-2007 10:57 PM

Re: Argument-Dependent Lookup
 
On May 15, 7:40 am, siddhu <siddharth....@gmail.com> 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.



All times are GMT. The time now is 06:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57