Xem xét ++ mã C sau,Thành phần dữ liệu lớp mẫu cơ sở không hiển thị trong lớp mẫu có nguồn gố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;
}
tôi đã nhận lỗi biên dịch: Trong chức năng thành viên void B<Derived>::foo()
:
template_inherit.cpp:12: error: 'usable_' was not declared in this scope.
Tại sao vậy? Bất kỳ sửa chữa tốt?
Trình biên dịch này là gì? –
'struct B: A < B>' wat. –
GManNickG
@GMan haha CRTP ngụy trang :) –