** I am trying to compile a program that looks like the following but the compiler cannot recognize which class the nested class belongs to: #include <iostream> using namespace std; template <typename T> struct A { class B; friend class B; }; template <> struct A<void> { class B; friend class B; }; template <typename T> struct A<T>::B { B() { cout << __PRETTY_FUNCTION__ << endl; } }; int main() { A<void>::B b; } ** Reports: nesttempspecbug.cpp: In function `int main()': nesttempspecbug.cpp:35: error: aggregate `A<void>::B b' has incomplete type and cannot be defined
This error message is correct as you specialized A<void> but you also need to specialize the nested class as the non specialized version of the nested function will not be used.
** Then if I add the following: template <> struct A<void>::B { B() { cout << __PRETTY_FUNCTION__ << endl; } }; ** I get: nesttempspecbug.cpp:35: error: explicit specialization of non-template `A<void>::B' nesttempspecbug.cpp:35: error: explicit specialization of non-template `A<void>::B'
You just want: struct A<void>::B { B() { cout << __PRETTY_FUNCTION__ << endl; } }; Since you already specialized A<void>, you don't need to specialize A<void>::B.