C ++ - How to initialize a separate class constructor from a class constructor?

I am basically trying to create a local (and private) instance of a class deltaKinematicsin a classgeneticAlgorithm

In the file geneticAlgorithm.hI have:

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

class GeneticAlgorithm {
  //private  
    DeltaKinematics deltaRobot;

public:

    GeneticAlgorithm(); //constructor

};

This is all fine, but when I go to declare a constructor geneticAlgorithm, I cannot figure out how to build an instancedeltaKinematics

This is the constructor 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";
}

How do I start initializing this local instance?

+5
source share
2 answers

Member Initializer List:

GeneticAlgorithm::GeneticAlgorithm() : deltaRobot(100) {
}
+11
source
GeneticAlgorithm::GeneticAlgorithm() : deltaRobot(100) {
    cout << "Genetic Algorithmic search class initiated \n";
}

: : . , , , .

+3

All Articles