I am creating a student object and want to call my constructor using a loop here is my code can anyone tell me what i am doing wrong.
I want the loop to run and each time access the constructor and ask for input
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int N = 0;
cout<<"Enter the number of students to be created"<<endl;
cin>>N;
// the ** makes the array of pointer not array of objects
Student **pointerArray;
// crerate all the Pointer
pointerArray = new (Student*)[N];
// create all the objects
for (int i=0; i< N; i++)
{
pointerArray[i] = new Student(i);
}
As for the student info in the loop. I don't think you need new Student(i), you need new Student(info), where info is the student info you asked the user to enter in the loop.
I have fixed that, the current error is
\main.cpp array bound forbidden after parenthesized type-id
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int main(int argc, char *argv[])
{
int N = 0;
cout<<"Enter the number of students to be created"<<endl;
cin>>N;
// the ** makes the array of pointers not an array of objects
Student **studentObject;
// create all the Pointers
studentObject = new (Student*)[N];
// create all the objects
for (int i=0; i< N; i++)
{
studentObject[i] = new Student(i);
}
system("PAUSE");
return EXIT_SUCCESS;
}