我有以下代码:
void module_books::show_item(int n, TABLE<BOOK> b) {
cout<<"Title: "<<b[n]->title<<"\n";
cout<<"Author: "<<b[n]->author<<"\n";
cout<<"Issue: "<<"no. "<<b[n]->issueno<<". "<<b[n]->city<<", "<<b[n]->publisher<<", "<<b[n]->year<<"\n";
cout<<"ISBN: "<<b[n]->isbn<<"\n";
cout<<"Pages count: "<<b[n]->pages<<"\n";
cout<<"Information: Loan count: "<<b[n]->outcount<<". ";
if(b[n]->damaged) cout<<"DAMAGED ";
if(b[n]->out) cout<<"LOANED";
cout<<"\n\n";
}
int module_books::add_item(TABLE<BOOK> &b) {
int _year, _issueno, _pages;
bool _damaged=false;
string _title, _author, _isbn, _publisher, _city, stmp;
cout<<"You're adding new book to the list.\nFill in the following fields:\n\n";
cout<<"Title: "; getline(cin,_title);
cout<<"Author: "; getline(cin,_author);
cout<<"Issue no: "; cin>>_issueno; cin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
cout<<"Issued in (city): "; getline(cin,_city);
cout<<"Issuer: "; getline(cin,_publisher);
cout<<"Issued in (year): "; cin>>_year; cin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
cout<<"ISBN: "; getline(cin,_isbn);
cout<<"Pages count: "; cin>>_pages;
cout<<"Is damaged? (y/n): "; cin>>stmp; cin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
if(stmp=="y" || stmp=="yes" || stmp=="Y" || stmp=="Yes" || stmp=="YES") _damaged=true;
int n=b.size();
b.push_back(BOOK(_title,_author,_publisher,_city,_isbn,_year,_issueno,_pages,_damaged));
cout<<"\nThe book has been added:\n\n";
show_item(n,b);
cout<<"\nreturning\n";
return n;
}
BOOK只是一个包含一些成员变量的结构。 TABLE是一个结构模板,就像STL向量一样(我不允许使用向量,所以必须编写我自己的模板,此时它正在使用静态数组T ar[100]
)。
问题在于我收到了已添加该书的消息,并且show_item函数打印了所有数据,但我没有收到“返回”消息。
我尝试设置断点,以便show_table
函数到达结尾}
,但程序永远不会到达“返回”消息。
此代码可能有什么问题?我在MinGW上使用32位QTCreator。我的操作系统是64位Win8.1,如果这会有帮助......