Shape *shape[100];//global scope
Square sqr;//global scope
void inputdata() {
int len,width;
cout << "enter length";
cin >> len;
cout << "enter width";
cin >> width;
Square sqr(len,width);
shape[0] = &sqr;
//----> if shape[0]->computeArea(); here works fine.
}
void computeArea() {
shape[0]->computeArea(); // --> run fail error
}
Shape是父类,Square是子类。都有computeArea();对象继承虚函数运行失败错误
当代码达到computeArea()我有一个奇怪的运行失败错误。该程序只是终止,没有给我任何错误,我找到并修复它......它只是显示运行失败并停止程序。
该程序能够正常运行,并显示 - > computeArea()如果代码是在inputdata()内,但是当我分开它时,它只是无法正常运行。任何解决方案?
从您发布的代码,我没有看到一个问题,你可能有错误的东西在其他地方。 – 2013-05-08 13:32:05