How to discard const in c++
- by Vincenzo
This is what I'm trying to do and I can't:
#include <string>
using namespace std;
class A {
bool has() const { return get().length(); }
string& get() { return s; }
private:
string s;
};
The error I'm getting is:
passing ‘const A’ as ‘this’ argument of
‘std::string& A::get()’ discards qualifiers
I understand what the problem is, but how can I fix it? I really need has() to be const. Thanks.