Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 friend
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

rusted
New Member

2 Posts

Posted - Jun 30 2004 :  5:32:04 PM  Show Profile


second_func shouldn't appear in this list, isn't it?

jpizzi
Tomato Guru

USA
642 Posts

Posted - Jun 30 2004 :  8:02:01 PM  Show Profile
The problem with your example is that friend functions are not defined when they are declared as a friend. They are defined elsewhere. Try removing the body of the friend function to outside the class and see if the suggestion changes.

As you have it, the function is declared as a friend, but is actually a member! I would be surprised if it compiled successfully.

Joe Pizzi
Go to Top of Page

ivan
Ketchup Master

Russia
75 Posts

Posted - Jun 30 2004 :  10:07:22 PM  Show Profile
quote:
Originally posted by jpizzi

The problem with your example is that friend functions are not defined when they are declared as a friend. They are defined elsewhere. Try removing the body of the friend function to outside the class and see if the suggestion changes.

As you have it, the function is declared as a friend, but is actually a member! I would be surprised if it compiled successfully.


quote:
(from MSDN)

C++ Language Reference

Defining Friend Functions in Class Declarations

Friend functions can be defined inside class declarations. These functions are inline functions, and like member inline functions they behave as though they were defined immediately after all class members have been seen but before the class scope is closed (the end of the class declaration).

Friend functions defined inside class declarations are not considered in the scope of the enclosing class; they are in file scope.



Personally I didn't know it was possible, but MSDN doesn't mark it as 'Microsoft extension'. In any case, since it's correct for VC++, VA X indeed shouldn't treat that function as a member of the class.
Go to Top of Page

Uniwares
Tomato Guru

Portugal
2321 Posts

Posted - Jun 30 2004 :  11:36:59 PM  Show Profile
Known bug, old bug. search the forum for "friend" and you find some references. In all cases the friend (function, struct, class) is listed as member.

Personally I find it pretty sick to "define" a friend inside an class. But thats my personal opinion.
Go to Top of Page

Sir Zooro
Junior Member

Poland
15 Posts

Posted - Jul 01 2004 :  08:25:39 AM  Show Profile
This now works in VS.NET 2003, but somewhere I read that you can't compile this if friend function is defined outside class:

template<class T, int N>
class Test {
public:
	T tab[N];

	friend void f(Test<T,N> &c)
	{
	}
};


Best Regards,
Daniel
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000