考虑以下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: 错误:'usable_'在此作用域中未声明。
为什么会出现这种情况?有什么好的解决方法吗?