Possible Duplicate:
Why doesn't a derived template class have access to a base template class' identifiers?C++、次のプログラムのテンプレート、コンパイルエラー
翻訳
ああ
#ifndef A_H
#define A_H
template <class T>
class A
{
protected :
T a;
public:
A(): a(0) {}
};
#endif
Bhの
#ifndef B_H
#define B_H
template <class T>
class A;
template <class T>
class B: public A <T>
{
protected:
T b;
public:
B() : A<T>(), b(0) {}
void test() { b = 2 * a;} //a was not declared in this scope
};
#endif
は、エラーが発生します。「この中で宣言されていませんでした範囲"。 (Netbeans 6.9.1)。
しかし、建設
void test() { b = 2 * this->a;}
が正しいか...問題はどこにありますか?
フォワード宣言またはファイルインクルードディレクティブを使用する方が良いですか?
B.h
template <class T>
class A;
対
#include "A.h"
http://www.comeaucomputing.com/techtalk/templates/#whythisarrowを参照してください。 –
[なぜ派生したテンプレートクラスは、ベーステンプレートクラスの識別子にアクセスできませんか?](http:// stackoverflow。 com/questions/1239908/why-doesnt-a-derived-template-class-have-a-base-template-class-identi) –