基本上我想要实现的是在类 deltaKinematics 中创建类 geneticAlgorithm 的本地(和私有(private))实例

geneticAlgorithm.h 文件中,我有:

class DeltaKinematics; //class is defined in separate linked files

class GeneticAlgorithm {
  //private
    DeltaKinematics deltaRobot;

public:

    GeneticAlgorithm(); //constructor

};

这一切都很好,但是当我去声明 GeneticAlgorithm 构造函数时,我无法弄清楚如何构造 DeltaKinematics 的实例

这是 geneticAlgorithm.cpp 构造函数:
GeneticAlgorithm::GeneticAlgorithm(){ //The error given on this line is "constructor for 'GeneticAlgorithm' must explicitly initialize the member 'deltaRobot' which does not have a default constructor"

    DeltaKinematics deltaRobot(100); //this clearly isn't doing the trick

    cout << "Genetic Algorithmic search class initiated \n";
}

我如何着手初始化该本地实例?

最佳答案

成员初始化列表:

GeneticAlgorithm::GeneticAlgorithm() : deltaRobot(100) {
}

关于C++-如何初始化与类的构造函数不同的类的构造函数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6055154/

10-10 23:19