Given 2 classes:
...
class Grades{
public:
Grades(int numExams) : _numExams(numExams){
_grdArr = new double[numExams];
}
double GetAverage() const;
...
private: // The only data members of the class
int _numExams;
double *_grdArr;
};
class Student{
public:
Student(Grades g) : _g(g){
}
...
private: // The only data members of the class
Grades _g;
};
...
And, a short main program:
int main(){
int n = 5; // number of students
Grades g(3); // Initial grade for all students
// ... Initialization of g – assume that it's correct
Student **s = new Student*[n]; // Assume allocation succeeded
for (int it = 0 ; it < n ; ++it){
Grades tempG = g;
// ... Some modification of tempG – assume that it's correct
s[it] = new Student(tempG);
}
// ...
return 0;
}
This code works fine. But by typo mistake the line:
Grades tempG = g;
has changed to:
Grades tempG = n;
and still it passes the compilation. What simple change can i do in the code (the main() code) to get a compilation error by that typo mistake?