Che*_*Alf 2 c++ constructor virtual-functions pure-virtual
考虑到T来自类的构造函数的(直接或间接)成员函数的虚拟调用,T最多可以归结为T实现,下面的代码,具有不合格的调用,是否具有未定义的行为?
注意,为了避免噪音:如果您认为在从构造函数调用时不会虚拟调用成员函数,那么请不要在此处回答或评论,而是在单独的SO问题中提出该问题.谢谢.
struct Baze
{
virtual void foo();
virtual void bar() = 0;
Baze(){ foo(); bar(); }
};
void Baze::foo() {}
void Baze::bar() {}
struct Derived: Baze
{
void bar() override {}
};
int main()
{
Derived{};
}
Run Code Online (Sandbox Code Playgroud)