基本上我想要实现的是在类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) {
}