Commit bc4d0f585ba01b051c9383a1eed6fa04049289d6
1 parent
1f755849
Updated Koenig lookup example
Showing
1 changed file
with
25 additions
and
3 deletions
examples06/01-operator/operator.cpp
| 1 | #include <iostream> | 1 | #include <iostream> |
| 2 | 2 | ||
| 3 | +namespace ours | ||
| 4 | +{ | ||
| 5 | + class example | ||
| 6 | + { | ||
| 7 | + int a = 0; | ||
| 8 | + friend std::ostream& operator<< (std::ostream& o, example a); | ||
| 9 | + }; | ||
| 10 | + | ||
| 11 | + std::ostream& operator<< (std::ostream& o, example a) | ||
| 12 | + { | ||
| 13 | + o << a.a; | ||
| 14 | + return o; | ||
| 15 | + } | ||
| 16 | +} | ||
| 17 | + | ||
| 3 | int main() | 18 | int main() |
| 4 | { | 19 | { |
| 20 | + std::cout << 10; | ||
| 21 | + | ||
| 22 | + std::cout.operator<<(10); | ||
| 23 | + | ||
| 24 | + ours::example e,f,g; | ||
| 25 | + | ||
| 26 | + std::cout << e << f << g; | ||
| 5 | 27 | ||
| 6 | -//std::cout << "ala\n" << "ola\n"; | 28 | + ((std::cout << e) << f) << g; |
| 7 | 29 | ||
| 8 | -std::operator<<(std::operator<<(std::cout, "ala\n"), "ola\n"); | 30 | + ours::operator<<(ours::operator<<(ours::operator<<(std::cout,e),f),g); |
| 9 | 31 | ||
| 10 | -} | ||
| 11 | \ No newline at end of file | 32 | \ No newline at end of file |
| 33 | +} |