给定2个类:
...
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;
};
...
而且,一个简短的主程序:
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;
}
这段代码工作正常。但是由于拼写错误,该行:
Grades tempG = g;
已更改为:
Grades tempG = n;
它仍然通过了编译。我可以在代码(main() 代码)中做哪些简单的更改,以通过该拼写错误获得编译错误?