const int* const Method3(const int* const&) const;
Run Code Online (Sandbox Code Playgroud)
有人可以解释每个const的用法吗?
这就是我想要做的事情,我不能:
#include <string>
using namespace std;
class A {
public:
bool has() const { return get().length(); }
string& get() { /* huge code here */ return s; }
private:
string s;
};
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
passing ‘const A’ as ‘this’ argument of
‘std::string& A::get()’ discards qualifiers
Run Code Online (Sandbox Code Playgroud)
我明白问题是什么,但我该如何解决呢?我真的需要has()是const.谢谢.