编辑 - 将问题更多地放在上下文中。
鉴于:
struct Base
{
...
};
struct Derived : public Base
{
...
};
class Alice
{
Alice(Base *const _a);
...
};
class Bob : public Alice
{
Bob(Derived *const _a);
...
};
当我尝试实施
Bob::Bob(Derived *const _d) : Alice(static_cast<Base*const>(_d)) { }
这没用。aconst_cast
对我来说没有意义,因为我不想改变常量,而且我没有改变我所指的内容,那么为什么 g++ 会告诉我
invalid static_cast from type ‘Derived* const’ to type ‘Base* const’
? 如果我省略演员表,它会说
no matching function for call to ‘Alice::Alice(Derived* const)’
如果有人能对此有所了解,将不胜感激。