我很久以来就遇到了错误,接下来,我正在学习,我想我不明白这个错误.
droid.cpp: In function ‘std::ostream& operator<<(std::ostream&,const Droid&)’: droid.cpp:94:30: error: passing ‘const Droid’ as ‘this’ argument of ‘std::string Droid::getId()’ discards qualifiers [-fpermissive]
第94行:
std::ostream& operator<<(std::ostream &os,Droid const & a) os << "Droid '" << a.getId() << "'," << *a.getStatus() << "," << a.getEnergy() << std::endl;
和听众:
std::string getId();
我对“operator<<”,a.getId,a.getStatus,a.getEnergy中的3个调用有相同的错误. 有人可以向我解释一下编译器在说什么吗?