ここに私がする必要があるものがあります:
#include <iostream>
using namespace std;
class A
{
public :
virtual void fa() = 0;
};
template <typename type>
class B : public A
{
protected :
int v_b;
};
template <typename type>
class C : public B<type>
{
public :
void fa()
{
// whatever action that try to access v_b
cout << "v_b = " << v_b << endl;
}
};
int main()
{
C<int> toto;
toto.fa();
return 0;
}
そしてここにg ++出力があります:
test.cpp: In member function ‘void C<type>::fa()’:
test.cpp:25:29: error: ‘v_b’ was not declared in this scope
私の理解では、v_b は B の保護されたメンバーであるため、C でアクセスできます。A と B はどちらも抽象クラスであり、インスタンス化するには、クラス C で A の f_a() メソッドをオーバーライドする必要があります。コンパイラが私にこれを言っているので
test.cpp: In member function ‘void C<type>::fa()’:
ではない
‘void A::fa()’:
v_b 変数がスコープに存在しない理由がわかりません。これはテンプレートの使い方に問題がありますか?
誰かが私を助けてくれますか?
どうも
編集 :
ここで提案されているように this->v_b または B<type>::v_b を使用しようとしましたが、うまくいきました! あなたの助けをthx