468,511 Members | 1,531 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,511 developers. It's quick & easy.

unnamed namespace and friend

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
1 1508

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.

Similar topics

1 post views Thread by Anthony | last post: by
4 posts views Thread by marco_segurini | last post: by
1 post views Thread by Marco Jez | last post: by
3 posts views Thread by Sandy | last post: by
2 posts views Thread by dioscuroi | last post: by
9 posts views Thread by Ivan Mascovich | last post: by
3 posts views Thread by Tomás | last post: by
1 post views Thread by vsgdp | last post: by
3 posts views Thread by CrazyJohn | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.