Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > unnamed namespace and friend

Reply
Thread Tools

unnamed namespace and friend

 
 
marco_segurini
Guest
Posts: n/a
 
      02-03-2005
Hi,

I like to know if this code is legal:

namespace
{
void unnamed_ns(){}
}

class test
{
friend void unnamed_ns();
};

int main()
{
unnamed_ns();
}

because the c++ compiler of vs2003 return me this error

error C2668: 'unnamed_ns' : ambiguous call to overloaded function
could be 'void unnamed_ns(void)'
or 'void `anonymous-namespace'::unnamed_ns(void)'

while all is fine for Comeau Online

Thanks a lot.
Marco.
 
Reply With Quote
 
 
 
 
msalters
Guest
Posts: n/a
 
      02-03-2005

marco_segurini wrote:
> Hi,
>
> I like to know if this code is legal:
>
> namespace { void unnamed_ns(){} }
>
> class test {friend void unnamed_ns(); };
>
> int main() {
> unnamed_ns();
> }


Yes. The friend declaration refers to a name that can be found
in the enclosing scope (in this case, global) because an unnamed
namespace implies a using directive. (7.3.1.1)

Regards,
Michiel Salters

 
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
Experiment with unnamed namespace and template Johannes Schaub (litb) C++ 4 10-13-2010 07:18 PM
unnamed namespace and friend method John Ratliff C++ 9 02-08-2008 04:17 PM
friend and unnamed namespace Ivan Mascovich C++ 9 03-03-2006 01:53 PM
using a class in an unnamed namespace as friend marco_segurini C++ 4 06-16-2004 03:10 PM
C++ programmers! How do you use unnamed 'namespace's ? Razmig K C++ 3 09-05-2003 06:52 AM



Advertisments