c++ - error when accessing a base class
- Alok (6/24) Aug 20 2007 As I understand, base class members are not accessible only when the
- Walter Bright (3/29) Aug 25 2007 It's incorrect when talking about template classes. See the references
- =?UTF-8?B?RGllZ28gU8OhbmNoZXo=?= (7/35) Aug 30 2007 There are some problems:
Hi, With reference to the following FAQ item:As I understand, base class members are not accessible only when the derived class (template) has members with the same name. Is this incorrect? Being unable to access base class sounds naive! Best regards - AlokThe compiler gives me an error when accessing a base class? With the code: template <class T> struct Base { int m_member; }; template <class T> struct Derived : public Base<T> { Derived() : m_member(0) {} }; the compiler gives an error that the m_member or any other members of Base<T> are not found. Although other compilers accept such code, it is incorrect according to the C++98 Standard 14.6.2-2 and 14.6.2.1-1. Base<T> is a dependent type, and so it is not in scope for template class Derived.
Aug 20 2007
Alok wrote:Hi, With reference to the following FAQ item:It's incorrect when talking about template classes. See the references in C++98.As I understand, base class members are not accessible only when the derived class (template) has members with the same name. Is this incorrect? Being unable to access base class sounds naive!The compiler gives me an error when accessing a base class? With the code: template <class T> struct Base { int m_member; }; template <class T> struct Derived : public Base<T> { Derived() : m_member(0) {} }; the compiler gives an error that the m_member or any other members of Base<T> are not found. Although other compilers accept such code, it is incorrect according to the C++98 Standard 14.6.2-2 and 14.6.2.1-1. Base<T> is a dependent type, and so it is not in scope for template class Derived.
Aug 25 2007
Alok wrote:Hi, With reference to the following FAQ item:There are some problems: 1) Neigther 'Base' nor 'Derived' (This types are structers) 2) The Base's member 'm_member' is private. 3) The error is beacause when you create a instance of Derived this struct/class haven't a public constructor. DiegoAs I understand, base class members are not accessible only when the derived class (template) has members with the same name. Is this incorrect? Being unable to access base class sounds naive! Best regards - AlokThe compiler gives me an error when accessing a base class? With the code: template <class T> struct Base { int m_member; }; template <class T> struct Derived : public Base<T> { Derived() : m_member(0) {} }; the compiler gives an error that the m_member or any other members of Base<T> are not found. Although other compilers accept such code, it is incorrect according to the C++98 Standard 14.6.2-2 and 14.6.2.1-1. Base<T> is a dependent type, and so it is not in scope for template class Derived.
Aug 30 2007