【发布时间】:2021-10-03 07:50:57
【问题描述】:
这不会编译:
struct Base
{
void something( int a ) { }
};
struct Derived : public Base
{
static void something()
{
std::unique_ptr<Derived> pointer = std::make_unique<Derived>();
pointer->something( 11 );
}
};
可以使用using Base::something 进行修复,但即使在方法内部也可以使继承工作如宣传的那样?
【问题讨论】:
-
注意
Derived()中的函数是static而Base中的函数不是,所以它不会覆盖它。另外,即使Derived中的函数不是静态的,Base中的函数也需要声明为virtual才能被覆盖 -
我认为问题在于为什么不能从
Derived:::something()自动访问Base::something(int)。 -
什么是“广告”?还有谁?
标签: c++ oop inheritance c++17