diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-09-06 12:24:03 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-09-06 12:24:03 +0200 |
commit | 95bfddc4329119535cf2fb47bef3c1b87f61e411 (patch) | |
tree | 69c5b24bfe8fb7028450aaed7f0abf38f40329da /C++/Friend Operator.wiki | |
parent | ons 31 aug 2022 17:37:49 CEST (diff) | |
download | wiki-public-95bfddc4329119535cf2fb47bef3c1b87f61e411.tar.gz wiki-public-95bfddc4329119535cf2fb47bef3c1b87f61e411.tar.xz |
tis 6 sep 2022 12:24:03 CEST
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; +} +}}} |