Firstly, I have doubts about your function pow. I don't know how and where you have defined it. Is this the <cmath> built-in function that you are using?
Assuming it is correct, the other thing that is confusing me is that all the member variables of your PopulationFrequency class are either protected or private. This means they are not accessible from your Evolution class. Why would you want such an arrangment?
Lastly, since you are dealing with pointers and dynamic memory allocation, you will have to be careful with the different constructors (especially copy and assignment) and destructor of class PopulationFrequency to avoid unexpected crashes.
Ok, seemingly the problem is because the vector objarray is a local variable of Evolution Constructor. It gets deleted once the code exits from this constructor. The vector should be declared in the Evolution class definition along with your other protected/private variables.
However, I am repeating, the objarray vector will not be of any use even then, because all the variables of PopulationFrequency are either protected or private and are inaccessible from the class Evolution.
Are you declaring it in the Evolution class? Then what are N_times_PopulationFrequency, loci and nindividuals? loci is a member of PopulationFrequency and not Evolution.
Try declaring your Evolution class like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class Evolution
{
protected:
private:
int m_rows;
std::vector<PopulationFrequency> objarray;
public:
Evolution(int);
};
Evolution::Evolution(int nrow)
{
m_rows = nrow * nrow;
for (int i=0; i<m_rows; i++)
objarray.push_back( PopulationFrequency(3,10) );
}
How do you know nothing gets pushed? What have you tried to output? Please remember, at present your code is such that even if you manage to create the array objarray, you will not be able to access its elements' member variables as all the variables have been declared as protected or private.
If you are certain that the elements are not being pushed, you can try doing: