Apologize for my english. I'm trying to solve a very simple problem in c++. But i'm new in c++ so can't solve this :( I'm trying to use operator overloading with header files. For new I'm trying to implementing this question. But I got error in getStatusPoint method.
int getStatusPoint(Alien const& alien)
{
return alien.getHeight()*alien.getWeight()*aliean.getGender();
}
bool Alien::operator>(const Alien& alien) const {
return(getStatusPoint(*this) > getStatusPoint(alien));
}
If I use don't use getStatusPoint method then its working fine. Can anyone please help me to solve this question using getStatusPoint().
Your error message suggests that neither getHeight nor getWeight is marked as const. You should define
class Alien ... {
public:
int getHeight() const { ... }
...
};
Your implementation should neither write access to a field of your class nor call a non-const method of your class.
像int getHeight() const;
一样声明您的getHeight()
, getWeight()
和getGender()
const int getHeight() const;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.