关于isbn的问题
本帖最后由 错过了一个亿 于 2020-5-7 08:36 编辑为什么我这样写编译器报错?
平台:
Ubuntu 20.04 desktop amd64
gnu g++ 9.30
#include <iostream>
#include "Sales_item.h"
int main(){
Sales_item item1,item2;
std::cout<<"输入相同ISBN的书本:"<<std::endl;
std::cin>>item1>>item2;
//判断ISBN是否相等
if (item1.same_isbn(item2)){
std::cout<<item1+item2<<std::endl;
return 0;
}else{
std::cerr<<"Date must refer to same ISBN!!!"<<std::endl;
return -1;
}
}
编译器报错内容:
file.cpp: In function ‘int main()’:
file.cpp:8:12: error: ‘class Sales_item’ has no member named ‘same_isbn’
8 |if (item1.same_isbn(item2)){
| ^~~~~~~~~
这样写就不会报错
#include <iostream>
#include "Sales_item.h"
int main(){
Sales_item item1,item2;
std::cout<<"输入相同ISBN的书本:"<<std::endl;
std::cin>>item1>>item2;
//判断ISBN是否相等
if (item1.isbn()==item2.isbn()){
std::cout<<item1+item2<<std::endl;
return 0;
}else{
std::cerr<<"Date must refer to same ISBN!!!"<<std::endl;
return -1;
}
}
注意看报错内容,而且,你这个是关于语言的,并不是关于isbn的,
class Sales_item’ has no member named ‘same_isbn’
Sales_item类,没有成员same_isbn
页:
[1]