1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Foo { int a; public: Foo(int i) : a(i) {} template<typename T> auto foo() -> decltype(a) { return a; } auto foo() -> decltype(a) { return a; } }; int main() { Foo f(0); f.foo(); // works fine f.foo<float>(); // error } |
Y2xhc3MgRm9vIHsKICAgIGludCBhOwpwdWJsaWM6CiAgICBGb28oaW50IGkpIDogYShpKSB7fQogICAgdGVtcGxhdGU8dHlwZW5hbWUgVD4KICAgIGF1dG8gZm9vKCkgLT4gZGVjbHR5cGUoYSkgewogICAgICAgIHJldHVybiBhOwogICAgfQogICAgYXV0byBmb28oKSAtPiBkZWNsdHlwZShhKSB7CiAgICAgICAgcmV0dXJuIGE7CiAgICB9Cn07CgppbnQgbWFpbigpIHsKICAgIEZvbyBmKDApOwogICAgZi5mb28oKTsgLy8gd29ya3MgZmluZQogICAgZi5mb288ZmxvYXQ+KCk7IC8vIGVycm9yCn0=
prog.cpp: In function 'int main()': prog.cpp:2:9: error: 'int Foo::a' is private prog.cpp:17:18: error: within this context prog.cpp:2:9: error: 'int Foo::a' is private prog.cpp:17:18: error: within this context
-
result: Compilation error (maybe you wish to see an example for C++11)


