Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
About friend declaration
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="WaterWalk, post: 3551650"] I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend void func() { printf("func in %s\n", __FILE__); } }; } int main() { ns1::func(); } ---End Example1--- gcc: compiles and works VC++: compile error: 'func': candidate function(s) not accessible Example2: -file1.cpp namespace ns1 { class Test { friend void func(); }; } int main() { ns1::func2("abc"); } -file2.cpp namespace ns1 { void func() { printf("func in %s\n", __FILE__); } } ---end Example2--- gcc: compiles and works VC++: compiles and works I'm rather confused. Does a friend function declaration make it as if it's also declared in the enclosing namespace? At least in example2, it seems to be so. What about Example1? What is the right behavior? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
About friend declaration
Top