I bring here 3 versions of code, the first one causes a compilation error, the second and the third were compiled successfully.
Code 1:
I created class Bottom
is a nested class in Middle
which is a nested class in a template class Top
template <class>
struct Top {
struct Middle {
struct Bottom {};
};
void useclass(Middle::Bottom);
};
This code gives an error:
main.cpp:6:27: error: 'Top::Middle::Bottom' is not a type
void useclass(Middle::Bottom);
^
Code 2:
Similar to Code 1 but with Top
is a normal class (non-template)
struct Top {
struct Middle {
struct Bottom {};
};
void useclass(Middle::Bottom);
};
This code was compiled successfully without any errors
Code 3:
Similar to Code 1 but with method useclass
taking Middle
instead of Bottom
template <class>
struct Top {
struct Middle {
struct Bottom {};
};
void useclass(Middle);
};
This code was compiled successfully as well
Please tell me:
Why Code 1 can't be compiled, which rule of C++ prevents it from being compiled?
Is there any way to use a nested class in a nested class in a template class like
Bottom
as a type?