I've spent the whole day trying to figure out why this doesn't want to work, I'm extracting information from a text file and sending the values through as arrays to a constructor (which works fine, I can print out the values and they will display.) But I can't create an object of another class inside of the constructor without it going into an infinite loop.
My main File:
int main(int argc, char** argv)
{
string line;
ifstream myfile ("test1.txt");
string rows [15];
int index = 0;
string tempForSize[5];
double * sizeArray = new double[5];
int firstIntOccur =0;
string * arrForEquations = new string[12];
int equationCount = 0;
if (myfile.is_open()) {
while ( myfile.good() ) {
getline (myfile,line);
rows[index] =line;
index++;
}
myfile.close();
}
else
cout << "Unable to open file" << endl;
for(int i=0; i <12;i++) {
if(rows[i].find("EQUATIONS: ")!=string::npos) {
i++;
i++;
while(i <index) {
arrForEquations[equationCount]=rows[i];
equationCount++;
i++;
}
break;
}
if(rows[i].find(':')!=string::npos) {
firstIntOccur =rows[i].find(':');
tempForSize[i].assign(rows[i],firstIntOccur+2,rows[i].size());
}
}
for(int i =0;i <5; i++) {
sizeArray[i] = atof(tempForSize[i].c_str());
}
try
{
string * equations = arrForEquations;
GeneticAlgorithm a(sizeArray, equations, equationCount);
}
catch(string s)
{
cout << s << endl;
}
return 0;
}
The constructor of the GeneticAlgorithm Class:
GeneticAlgorithm::GeneticAlgorithm(double *& arr, string * sArr, int size) {
Equation ** e = new Equation*[size];
for(int i = 0; i < size; i++) {
e[i] = new Equation(sArr[i]);
}
}
The equation class works perfectly when strings are entered into it, I just can't figure out why this does not want to work.
Thanks in advance.