Hello I need to create an array of pointers for class dog is one class and showDog is the derived class. I need to input from a data file and store the variables to these classes. In the file there is a D for dog or S for showDog between each set of data. I am having trouble with the pointer part of the problem and am not quite sure what I am doing wrong. Here is the part of my code that I believe the problem is. Any help I could get I would greatly appreciate.
-thanks
const int NUM_DOGS = 10;
dog *dogList[NUM_DOGS];
showDog *showList[NUM_DOGS];
ifstream numdata;
numdata.open("pgm8.dat");
if ( !numdata ) // Check to make sure file was opened
{
cout << "Error opening file" << endl;
}
int i;
for(i=0;i<NUM_DOGS;i++)
{
string test, nn, cc;
double ww;
int se, sw;
numdata>>test;
cout <<" test= " << test << endl;
if (test == "D")
{ i++;
numdata>>nn;
i++;
numdata>>cc;
i++;
numdata>>ww;
dogList[NUM_DOGS] = new dog(nn, nn, ww);
}
else
{ i++;
numdata>>nn;
i++;
numdata>>cc;
i++;
numdata>>ww;
showList[i] = new showDog(nn, cc, ww, se, sw);
}
}
numdata.close();
//array output
for(i=0;i<NUM_DOGS;i++)
{
cout <<"dog items: " << dogList[i]->displayDog() << endl;
cout <<"showdog items: " << showList[i]->displayDog() << endl;
}
Also here is the data file
D
Fido
50
Black
S
Rover
25
Brown
3
1
D
Shep
10
White
S
Shaggy
80
Black
10
3