2010-10-15 15:01:00
代码如下:
1template <typename T>
2class foo
3{
4public:
5 class bar
6 {
7 public:
8 bar() {}
9 bar(const bar &) {}
10 bar(int) {}
11 operator T *() const
12 {
13 return 0;
14 }
15 bar operator + (int)
16 {
17 return *this;
18 }
19 };
20};
21
22int main()
23{
24 foo<int>::bar f;
25 size_t i = 1;
26
27 f + i;
28
29 return 0;
30}
注意:外层 class foo``` 和 ```template
都不能去掉。
这个代码应该通过编译么?还是应该报operator +
匹配歧义?
首发:http://www.cppblog.com/Streamlet/archive/2010/10/15/130016.html