lin*_*s77 10 c++ inheritance class variable-assignment
执行以下操作是安全的还是未定义的行为:
class Base
{
private:
int a;
};
class Derived : public Base
{
private:
int b;
};
Base x;
Derived y;
x = y; // safe?
Run Code Online (Sandbox Code Playgroud)
派生类中的额外位是否会被切掉?
是的,发生切片.但它并不是未定义的行为.
您可能会在C++中找到此条目 - 常见问题解答:http:
//www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.8