Thread overview | |||||
---|---|---|---|---|---|
|
August 21, 2007 error when accessing a base class | ||||
---|---|---|---|---|
| ||||
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
|
August 26, 2007 Re: error when accessing a base class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alok | 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.
|
August 30, 2007 Re: error when accessing a base class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alok | 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
|
Copyright © 1999-2021 by the D Language Foundation