www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - error when accessing a base class

↑ ↓ ← Alok <alokgovil hotmail.com> writes:
Hi,

With reference to the following FAQ item:

 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.


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 - Alok
Aug 20 2007
→ Walter Bright <newshound1 digitalmars.com> writes:
Alok wrote:
 Hi,
 
 With reference to the following FAQ item:
 
 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.


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!

It's incorrect when talking about template classes. See the references in C++98.
Aug 25 2007
→ =?UTF-8?B?RGllZ28gU8OhbmNoZXo=?= <diegos intersoft.com.ar> writes:
Alok wrote:
 Hi,
 
 With reference to the following FAQ item:
 
 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.


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 - Alok

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. Diego
Aug 30 2007