aboutsummaryrefslogtreecommitdiff
path: root/C++/Friend Operator.wiki
blob: a5e6730034fafe7e71361e9287af5bf332887ecd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
= Friend Operator =

{{{c++
#include <iostream>

class T {
	int x;

public:
	T (int x);

	friend std::ostream& operator<<(std::ostream&, const T&);
};

T::T (int x) {
	this->x = x;
}


std::ostream& operator<<(std::ostream& out, const T& t) {
	out << "T {" << t.x << "}";
	return out;
}

int main () {
	T t(10);

	std::cout << t << std::endl;
}
}}}