Number of Elements in an array of objects

I am trying to get the number of objects present in an array of objects, but it fails everytime. The code is as below:

here im trying to do the for loop without using the variable 'units'.

1
2
3
4
5
6
7
8
9
10
11
    cout<<"\n\nHow many personal records would you like to create: ";
    cin >>records;
  
    clsPeople *objPersons = new clsPeople [units];
    
    for(i=0;i<siezeof(*objPersons)/sizeof(clsPeople);i++)
    {
        cout<<"\n\nPlease enter the program details for the program " 
             <<i+1<<endl;
        objPersons [i].setNewPersonDetails();
    }
Last edited on
What you are trying to do is impossible, as objPersons is a pointer, not an array. Just use the variable 'units'. That's what it is for.
agree with the Zhuge
Topic archived. No new replies allowed.