template派生クラスから基底クラスへのメンバアクセスは明示的に指定する

完全に忘れていた


コンパイルエラー】

template <class T>
class Parent
{
   int m;
};

template <class T>
class Child : public Parent<T>
{
    void method()
    {
        printf("%d", m);	// undeclared identifier
    }
};


【修正版】

template <class T>
class Parent
{
    int m;
};

template <class T>
class Child : public Parent<T>
{
    typedef Parent<T> inherited;
	
    void method()
    {
        printf("%d", inherited::m);	// 親クラスを明示的に指定してアクセスしなければならない
    }
};


ちなみに、親クラスのtypedefはsuperにしたいところだが、Objective-C予約語なので使わないようにしている。