unnamed namespace and friend

M

marco_segurini

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.
 
M

msalters

marco_segurini said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top