考慮下面的C++代碼,基本模板類數據成員在派生模板類中不可見?
template <typename Derived>
struct A
{
bool usable_;
};
template <typename Derived>
struct B : A< B<Derived> >
{
void foo()
{
usable_ = false;
}
};
struct C : B<C>
{
void foo()
{
usable_ = true;
}
};
int main()
{
C c;
}
我得到的編譯錯誤:在成員函數void B<Derived>::foo()
:
template_inherit.cpp:12: error: 'usable_' was not declared in this scope.
這是爲什麼?任何好的解決方法
這是什麼編譯器? – 2010-11-17 23:11:33
'struct B:A < B>'wat。 –
GManNickG
2010-11-17 23:14:54
@GMan哈哈CRTP變相:) – 2010-11-17 23:18:34