Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Argument-Dependent Lookup

Reply
Thread Tools

Argument-Dependent Lookup

 
 
siddhu
Guest
Posts: n/a
 
      05-14-2007
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()
{

}

 
Reply With Quote
 
 
 
 
Old Wolf
Guest
Posts: n/a
 
      05-14-2007
On May 15, 7:40 am, siddhu <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you tell a Cisco router NOT to cache a DNS lookup? Terra Dactyl Cisco 5 01-07-2005 04:37 AM
Domain Lookup Fred Atkinson Cisco 4 11-16-2004 03:24 PM
No Lookup Fred Atkinson Cisco 2 10-30-2004 02:23 PM
Re: Lookup SSID Paul E Wireless Networking 0 09-01-2004 05:37 PM
string condition file - lookup logic jason@cyberpine.com Perl 0 08-10-2004 07:28 PM



Advertisments