This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Template base class: name lookup bug?


In this example program class Derived<T> inherits from Base<T>. Yet an
unqualified name lookup of a base class member fails within
Derived<T>::print. If the identifier is qualified (Base<T>::numberBase)
then it works.

foo.cc: In member function `void Derived<T>::print()':
foo.cc:16: error: `numberBase' was not declared in this scope

#include <cstdio>

template <class T>
class Base {
    protected:
        int numberBase;
};

template <class T>
class Derived : public Base<T> {
public:
    void print()
    {
        printf("bn = %d\n", numberBase);
    }
};

int main()
{
    Derived<int> d;
    d.print();
    return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]