-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweek14-app7.cpp
50 lines (36 loc) · 952 Bytes
/
week14-app7.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SFINAE: enable_if, and its relation with concepts
// ADL: argument dependent lookup, friend functions
// CRTP: curiously recurring template pattern
#include <iostream>
using namespace std;
namespace Mine
{
struct Bar
{
friend struct Foo;
};
struct Foo {
private:
int i = 1111;
public:
void print() const {
cout << "I am a Foo with value " << i << endl;
}
friend struct Bar;
friend void print(const Foo& foo); // this is still a free function not a method
};
void print(const Foo& foo) { // this is still a free function not a method
foo.print();
cout << "but I am free (with value = " << foo.i << ")" << endl;
}
}
int main()
{
// std::cout << "Hi" << std::endl;
// std::operator<<(std::cout, "");
cout << "Hi" << endl;
operator<<(std::cout, "");
auto foo = Mine::Foo{};
foo.print();
print(foo);
}