By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,169 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,169 IT Pros & Developers. It's quick & easy.

unnamed namespace and friend

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

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

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.