c++ - How to allow a member function that's defined inside the class declaration to be called by constant objects of said class -
i have book
class within namespace literature , following declaration implementation pair doesn't work:
namespace literature { class book{ public: //getter method condition check(){return status;} const bool operator==(const book&); bool operator!=(const book&); } }
the logical overload's declaration:
namespace literature{ bool book::operator==(const book& right) {return true;} bool book::operator!=(const book& right) {return false;} }
for reason, implementation operator !=
works while 1 ==
doesn't , instead states prototype ==
overload returns const bool
instead of bool
although answer j.alvaro.t shows done overcome problem. answer text misleading. main issue line of code:
condition check() {return status;} const
is grammatically malformed. intention make method const method , const keyword should appear before function body. characters after function body not parsed part of function definition , become part of next statement.
Comments
Post a Comment