new 的使用,能运行但不知为何会弹出Dug Assertion Failed!
程序代码:
#include <iostream> using namespace std; class Book { private: int pages; double price; char *bookname, *authors,*publishing_house; public: Book(){ bookname=new char[50]; authors=new char[50]; publishing_house=new char[50]; } ~Book(){ delete[](bookname);(bookname)=NULL; delete[]authors;(authors)=NULL; delete[]publishing_house;(publishing_house)=NULL; } void getXxx(); void setXxx(char *b,char *a,int pa,char*p, double pr); }; void Book::setXxx(char *b,char *a,int pa,char*p, double pr){ bookname=b; authors=a; pages=pa; publishing_house=p; price=pr; } void Book::getXxx(){ cout<<"书名:"<<bookname<<" 作者:"<<authors<<" 页数:"<<pages<<"页 "<<" 出版社: "<<publishing_house<<" 价格:"<<price<<endl; } int main() { cout<<"定义的两本书的信息:"<<endl; Book mybook; mybook.setXxx("《C++程序设计》","谭浩强编著",485,"清华大学出版社",36.00); mybook.getXxx(); cout<<endl; mybook.setXxx("《吹牛大王历险记》","拉斯伯等编著",149,"天津人民出版社",12.80); mybook.getXxx(); return 0; }