我在以下示例的 static_cast 中收到“错误:'A' 是 'B' 的不可访问基础”:
template<typename Derived>
class A {
protected:
void funA() { static_cast<Derived *> (this)->funB(); }
};
class B: protected A<B> {
public:
void funB() {}
void funC() { funA(); }
};
int main() {
B().funC();
return 0;
}
但是当使用 reinterpret_cast 或 C 风格的类型转换 ((Derived *)this)->funB() 时,它编译/运行良好。这种行为正确吗?
使用的编译器:gcc 版本 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC)。
谢谢。