我有一个基础课
class Keyframebase
{
private:
std::string stdstrName;
float time;
KeyframeType keyframeType;
public:
Keyframebase();
Keyframebase(KeyframeType keyType);
Keyframebase(const Keyframebase &key);
Keyframebase& operator = (const Keyframebase &key);
std::string getName();
};
Run Code Online (Sandbox Code Playgroud)
这是由另一个类派生的。
class SumKeyframeXYZ : public Keyframebase
{
private:
float x;
float y;
float z;
public:
SumKeyframeXYZ();
SumKeyframeXYZ(float x, float y, float z);
SumKeyframeXYZ(const SumKeyframeXYZ& key);
// const Sum_Position& operator=(const Container& container);
SumKeyframeXYZ& operator=(const SumKeyframeXYZ& key);
void setValue(float x, float y, float z);
};
Run Code Online (Sandbox Code Playgroud)
这是Derived类的副本构造函数。
SumKeyframeXYZ::SumKeyframeXYZ(const SumKeyframeXYZ& key) : Keyframebase(
key )
{
this->x …Run Code Online (Sandbox Code Playgroud) 我有一个容器类,有一个数据成员。
std::vector< std::unique_ptr<Sum_Function> > Functions;
Run Code Online (Sandbox Code Playgroud)
这就是我为向量增加价值的方式。
MaxSize是Sum_Function的子级。
void WavefrontRenderer::AddMaxSize()
{
Container cont;
std::unique_ptr<Sum_Function> ptrMaxSize = std::make_unique<SumMaxSize>();
cont.AddFunction(ptrMaxSize);
}
Run Code Online (Sandbox Code Playgroud)
这是Container类中Function的定义。
void Container::AddFunction(std::unique_ptr<Sum_Function> &func)
{
std::unique_ptr< Sum_Function > function(std::move(func));
this->Functions.push_back(function);
}
Run Code Online (Sandbox Code Playgroud)
这是向向量添加唯一指针的正确方法吗?