accessing members of a templated base class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Harrison

    accessing members of a templated base class

    This code fails to compile on Comeau C++ and VC++ 7.1 (with language
    extensions disabled)

    template <class T>
    struct B
    {
    T b;
    };

    template <class T>
    struct D : B<T>
    {
    void f() { b = 1; }
    };

    int main()
    {
    D<int> x;
    x.f();
    }

    Error messages refer to 'b = 1;' with the message 'undefined identifier b'.
    Substituting this->b for b or making B a non-template class both make the
    code compile.

    What's going on here? I was so surprised when I saw this on VC++ that I
    assumed it was a compiler bug, but apparently not.

    john


Working...