这在C ++ 11中是一个很好的做法(或者通常在OOP中)?
class Base
{
public:
Base(Base && other) = default;
};
class Derived : public Base
{
public:
Derived(Base && base, int derivedParam)
: Base(std::move(base)), derivedParam_m(derivedParam)
{
}
};
我能想到的唯一的缺点是,它允许使用其他派生类初始化派生类,如果误用,代码看起来会很奇怪。
class Shape;
class Circle : public Shape;
class Triangle : public Shape;
...
...
new Triangle{new Circle{p, r}, x, y, z}