Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: friend and namespace problem

Started 1 month ago by pi3orama
The C++ standard (Working Draft, n2914) said (at 3.3.2/9): [ Note: friend declarations refer to functions or classes that are members of the nearest enclosing namespace, but they do not introduce new names into that namespace (7.3.1.2). Function declarations at block scope and object declarations with the extern specifier at block scope refer to declarations that are members of an enclosing ...
Site: CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions  CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions - site profile
Forum: C++ (Non Visual C++ Issues)  C++ (Non Visual C++ Issues) - forum profile
Total authors: 2 authors
Total thread posts: 5 posts
Thread activity: no new posts during last week
Domain info for: codeguru.com

Other posts in this thread:

potatoCode replied 1 month ago
Your example does show that the standard is correct. Quote: Originally Posted by C++ standard Function declarations at block scope and object declarations with the extern specifier at block scope refer to declarations that are members of an enclosing namespace, is equally saying Code: namespace nsC { ...

pi3orama replied 1 month ago
Thank you for reply. The sample code is obscure, it doesn't show my problem. Look at the below code: Code: namespace N { class B; class C; } //#define TYPE N::C //#define ASSIGN do { x->i = 0;} while(0) #define TYPE N::B #define ASSIGN do {} while(0) void func(TYPE * x); namespace N { class B { int i; }; class C { int i; friend void func(TYPE * x); ...

pi3orama replied 1 month ago
Now I know the answer. The call of func(&x) is special. When lookup func, it should apply argument-dependent name lookup. According to [basic.lookup.argdep]: Any namespace-scope friend functions or friend function templates declared in associated classes are visible within their respective namespaces even if they are not visible during an ordinary lookup. 'friend' introduces hidden names...

potatoCode replied 1 month ago
You asked about namespace scope resolution and its relationship about friendship. No where in the OP had you mention anyting about preprocessors. You don't know the half the trouble obfuscating the C++ code through preprocessors can bring And templates? you were talking about templates? Oh fock me, I didnt' know that.

 

Top contributing authors

Name
Posts
pi3orama
3
user's latest post:
friend and namespace problem
Published (2009-11-06 00:59:00)
Now I know the answer. The call of func(&x) is special. When lookup func, it should apply argument-dependent name lookup. According to [basic.lookup.argdep]: Any namespace-scope friend functions or friend function templates declared in associated classes are visible within their respective namespaces even if they are not visible during an ordinary lookup. 'friend' introduces hidden names into namespace, it cannot be found by...
potatoCode
2
user's latest post:
friend and namespace problem
Published (2009-11-06 02:16:00)
You asked about namespace scope resolution and its relationship about friendship. No where in the OP had you mention anyting about preprocessors. You don't know the half the trouble obfuscating the C++ code through preprocessors can bring And templates? you were talking about templates? Oh fock me, I didnt' know that.

Related threads on "CodeGuru Forums - A Developer.com Community for C++, C#, VB, Java and .NET Solutions":

Related threads on other sites:

Thread profile page for "friend and namespace problem" on http://www.codeguru.com. This report page is a snippet summary view from a single thread "friend and namespace problem", located on the Message Board at http://www.codeguru.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity