Reply soon please: Friend Function, Basic Question.

Mar 22, 2013 at 7:45am
Can we do
1
2
3
void setX(int value){
	x = value;//Will it generate an error? If yes then why?
}

when
1
2
3
4
5
class a{
	int x;
public:	
	friend void setX(int);
};
Mar 22, 2013 at 8:28am
What kind of question is it?
Compile it, and see if there are errors.

In moment of doubt see http://www.cplusplus.com/doc/tutorial/inheritance/
Mar 22, 2013 at 8:55am
Yes, the compiler will issue an error because 'x' is non-static data member. The function shall accept an object of type a as a parameter that to change data member x of this object.

For example

friend void setX( a &obj, int value );
Topic archived. No new replies allowed.