本帖最后由 错过了一个亿 于 2020-5-7 08:36 编辑
为什么我这样写编译器报错?
平台:
Ubuntu 20.04 desktop amd64
gnu g++ 9.30
[C++] 纯文本查看 复制代码 #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;
}
}
编译器报错内容:
[Asm] 纯文本查看 复制代码 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)){
| ^~~~~~~~~
这样写就不会报错
[C++] 纯文本查看 复制代码
#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;
}
}
|