基本上我想要实现的是在类GeneticIngorithm中创建类deltaKinematics的本地(和私有)实例
在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) { }