From 9d5b7989268146f56f7a1d68f7e528e557fc921a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 24 Dec 2019 01:13:50 +0100 Subject: Tue, 24 Dec 2019 01:13:50 +0100 --- C++.wiki | 36 ++++++++++++++++++++++++++++++++++++ index.wiki | 1 + 2 files changed, 37 insertions(+) create mode 100644 C++.wiki diff --git a/C++.wiki b/C++.wiki new file mode 100644 index 0000000..b3dec5e --- /dev/null +++ b/C++.wiki @@ -0,0 +1,36 @@ += Contents = + - [[#C++ Examples|C++ Examples]] + - [[#C++ Examples#Friend operator|Friend operator]] + += C++ Examples = + +== Friend operator == + +{{{c++ +#include + +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; +} +}}} diff --git a/index.wiki b/index.wiki index 0401843..2295bd4 100644 --- a/index.wiki +++ b/index.wiki @@ -42,6 +42,7 @@ - [[Kläder]] - [[TaskApp]] - [[LiuformulaStudent]] +- [[C++]] * [[diary/diary|Dagbok]] -- cgit v1.2.3