2

Inheritance of class seems to work oddly inside a template class

template<typename T>
class b
{
public:
    class base
    {
    public:
        int a = 2;
    };

    class A : public base
    {
    public:
        void fun()
        {
            cout << a << endl;
        }
    };
};

When this piece of code is compiled, compiler would regard a as not declared(in A::fun()) However, if you write this->a instead of a, everything is ok

Question is: why won't the compiler interpret a as this->a(as it does in normal class)

Gabriel
  • 77
  • 1
  • 7
  • 5
    Nice example. It isn't immediately clear why `base::a` is dependent. But one must remember that it's actually `b::base::a`. And, `b::base` [may be specialized separately!](http://coliru.stacked-crooked.com/a/0ab98d823f022968). – StoryTeller - Unslander Monica Mar 12 '19 at 13:32

0 Answers0