I'm struggling with the constructor of one of my classes do to a member that is not initialized properly.
I have a class "Settings" that handles the setting I use for my simulations and a class Simulations that performs the simulation steps.
What I can't understand is why this code doesn't work as expected:
class Settings{ public: int n ; // a number I need to create properly a vector in my class simulation // ... rest of the code constructors etc to read values from files. // everything works fine and the values are assigned properly } class Simulation{ public: std::vector<int> v ; Settings *SP; Simulation(Settings *); } Simulation::Simulation(Settings *pS) :SP(pS), v(std::vector<int>(SP->n,0)) {} // the constructor doesn't work, // v is initialized but it is not created as a vector of size n, but 0. I think there is a problem in the way I use the constructor but I can't understand why.
By the way defining v inside the curly brackets works fine, I'm just curious to know why defining it the proper way doesn't work as expected!
Thanks a lot for the help!