小编sam*_*sam的帖子

复制派生类的构造方法

我有一个基础课

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)

c++ inheritance copy-constructor c++11

5
推荐指数
2
解决办法
143
查看次数

如何传递唯一指针

我有一个容器类,有一个数据成员。

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)

这是向向量添加唯一指针的正确方法吗?

c++ c++11

4
推荐指数
1
解决办法
117
查看次数

标签 统计

c++ ×2

c++11 ×2

copy-constructor ×1

inheritance ×1