Home Forums C Programming pointer of array of class Reply To: pointer of array of class

#3375
Humayan
Participant

You want to return the newly copied array from the function “AddGrade” ?  If so change your parameters to :
 

void AddGrade ( Grade **&  _numGrades , int &  _students )
{
   Grade ** gradeTemp = new Grade * [ _students + 1 ];
 
   for( int i = 0 ; i < _students + 1 ; i ++ )
       gradeTemp [ i ] = _numGrades [ i ] ;
   _students ++;
  //add code here to delete old "_numGrades" 
  _numGrades = gradeTemp;
}