friend function

why is it neccessary to define the friend functions outside the class?
Last edited on
It's not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

class Class
{
public:
	Class(int value) : var(value) {}
private:
	friend void print(Class obj) { std::cout << obj.var << std::endl; }
	int var;
};


int main()
{
	Class obj(123);
	print(obj);
}
Topic archived. No new replies allowed.