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 | template <typename T> struct A { struct B { }; }; struct C { typedef A<C> D; int f() { typename D::B p; return 0; } }; C gc; int x = gc.f(); template <> struct A<C> { struct B { B() { cout << "B::B()" << endl; } ~B() { cout << "B::~B()" << endl; } }; }; int main() { } |
dGVtcGxhdGUgPHR5cGVuYW1lIFQ+CnN0cnVjdCBBIHsKICAgIHN0cnVjdCBCIHsKICAgIH07Cn07CgpzdHJ1Y3QgQyB7CiAgICB0eXBlZGVmIEE8Qz4gRDsKCiAgICBpbnQgZigpIHsKICAgICAgICB0eXBlbmFtZSBEOjpCIHA7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9Cn07CgpDIGdjOwppbnQgeCA9IGdjLmYoKTsKCnRlbXBsYXRlIDw+CnN0cnVjdCBBPEM+IHsKICAgIHN0cnVjdCBCIHsKICAgICAgICBCKCkgewogICAgICAgICAgICBjb3V0IDw8ICJCOjpCKCkiIDw8IGVuZGw7CiAgICAgICAgfQoKICAgICAgICB+QigpIHsKICAgICAgICAgICAgY291dCA8PCAiQjo6fkIoKSIgPDwgZW5kbDsKICAgICAgICB9CiAgICB9Owp9OwoKaW50IG1haW4oKSB7Cn0K
prog.cpp: In member function ‘int C::f()’: prog.cpp:11: error: using ‘typename’ outside of template prog.cpp:11: warning: unused variable ‘p’ prog.cpp: At global scope: prog.cpp:20: error: specialization of ‘A<C>’ after instantiation prog.cpp:20: error: redefinition of ‘struct A<C>’ prog.cpp:2: error: previous definition of ‘struct A<C>’
-
result: Compilation error (maybe you wish to see an example for C++ 4.7.2)


