diff options
Diffstat (limited to '')
-rw-r--r-- | C++/Friend Operator.wiki | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/C++/Friend Operator.wiki b/C++/Friend Operator.wiki new file mode 100644 index 0000000..a5e6730 --- /dev/null +++ b/C++/Friend Operator.wiki @@ -0,0 +1,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; +} +}}} |