Example
template <typename T>
struct A
{
typedef A<T> super;
};
template <typename T>
struct B : A<T>
{
B() : super() {} // <-- HERE
};
int main()
{
}
With the MSVC compiler, this compiles as-is. However with gcc, I need to change super() to A<T>::super(). I’m assuming gcc is correct here, however could someone help me understand the rule here and which compiler is technically correct?
No, since it’s a dependant name, since
Ais a class template. You need to either fully qualify it, or use a shortcutB::super. The latter will also tell the compiler that it’s a dependant name and is very handy if the derived class also has lots of template parameters, sinceBwill expand toB<T, and, stuff>since it’s the injected class name.MSVC is wrong here thanks to its incomplete two-phase lookup. Basically, with MSVC, all the dependency checks and stuff only happen during instantiation of the template, while it should have been checked at declaration.