Base Class Initialization Pattern

whereas in visual C ++ the code below is accepted, g ++ will generate an error: "Derived class does not have a Base field name" which conforms to the standard?

template <class T> class Base { public: Base(){}; }; template <class T> class Derived:public Base<T> { public: Derived():Base(){} }; 

BTW: both accept

 Derived():Base<T>(){} 

meanwhile i will follow gcc

+4
source share
1 answer

MSVC ++ is invalid. Base is a pattern, not a type.

Note that in the normal case, Base scanned in the Derived<T> , which means that it will first find the entered class name inherited from Base<T> , which is of type Base<T> . But since you have a dependent base class, the name inherited from Base<T> was not found (the scope of the base class is not considered).

+6
source

All Articles