説明できない何かに出くわしただけです。次のコードはコンパイルされません
template<int a>
class sub{
protected:
int _attr;
};
template<int b>
class super : public sub<b>{
public:
void foo(){
_attr = 3;
}
};
int main(){
super<4> obj;
obj.foo();
}
ところが、に変更_attr = 3;
してthis->attr = 3;
も問題ないようです。
何故ですか?これを使わなければならない場合はありますか?
以前g++ test.cpp -Wall -pedantic
はコンパイルしていましたが、次のエラーが発生します
test.cpp: in member function 'void super<b>::foo()':
test.cpp:11:3: error: '_attr' was not declared in this scope