下面的代码报出bad allocation错误,求教为什么?
#include#include using namespace std; class Student { public: Student(); Student(int,string,float);//构造函数不能声明为虚函数,,,一般析构函数都声明都虚函数 //在声明构造函数时,在最左边加virtual,声明为虚函数,用同一种方式调用同一类族中不同类的所有的同名函数。当基类的一个成员函数声明为虚函数时,默认其派生类中的同名函数自动成为虚函数 virtual void display(); protected: int num; string name; float score; }; Student::Student():num(0),name("NULL"),score(0){} Student::Student(int n,string nam,float sco):num(n),name(nam),score(sco){ cout<<"this is Student constructor."< display(); pt=&grad1; pt->display(); grad1.display(); try{ Doctor doc1(3,"lili",97.3,2090,20);//此处报错!! pt=&doc1; pt->display(); doc1.display(); }catch(std::exception const &ex) { cout<
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
下次能仔细点嘛!