私は説明できない何かにつまずいた。次のコードは、私は何の問題もないように思わ_attr = 3;
this->attr = 3;
に変化したときには時にはこれを使用する必要がありますか?
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();
}
をコンパイルしません。
なぜですか?これを使用する必要がある場合はありますか?
私はコンパイルする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
[二相名前検索](上に読むhttp://blog.llvm.org/2009/12/dreaded-:
これを使用するには、別の非常に一般的な理由は、曖昧さの問題を解決することですtwo-phase-name-lookup.html)。 (このFAQ:[テンプレート由来のクラスがテンプレートベースクラスから継承したメンバーを使用すると、なぜエラーになるのですか?](http://www.parashift.com/c++-faq/nondependent-name -lookup-members.html)) – ildjarn