include iostream include utility template class struct TA struct frien

 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
#include <iostream>
#include <utility>
template <class T>
struct TA{
struct B{
friend std::ostream& operator<<(std::ostream &os, const B& b)
{
return os;
};
} m_b;
};
struct A{
struct B{
} m_b;
};
namespace std{
template<class T>
ostream& operator<<(ostream& os, const pair<T, T> &v)
{
os << "( " << v.first << ", "<< v.second << ")";
return os;
}
ostream& operator<<(ostream &os, const A::B& b)
{
return os;
}
}
int main (int argc, char * const argv[]) {
using namespace std;
TA<int> ta;
cout << ta.m_b; // error
A a;
cout << a.m_b; // ok
pair<int, int> p;
cout << p; //ok
return 0;
}