基本上我想要实现的是在类deltaKinematics
中创建类geneticAlgorithm
的本地(和私有)实例
在我的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";
}
如何初始化该本地实例?
答案 0 :(得分:12)
会员初始化人名单:
GeneticAlgorithm::GeneticAlgorithm() : deltaRobot(100) {
}
答案 1 :(得分:3)
GeneticAlgorithm::GeneticAlgorithm() : deltaRobot(100) {
cout << "Genetic Algorithmic search class initiated \n";
}
注意构造函数名后面的:
:它是类的成员数据变量的初始化序列的开始。它们显示为对其构造函数的调用,具有您想要传递的参数,并且应该与它们声明的顺序相同。