Reply soon please: Friend Function, Basic Question.

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);
};
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/
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.