Below is a partial class SafeString (omitting not related methods):
class SafeString
{
private:
char* _str = nullptr;
public:
operator std::string() const {
return { _str };
}
friend std::ostream& operator<<(std::ostream& os, const SafeStringInternal& ss) {
return os << ss.c_str();
}
const char* c_str() const noexcept {
return _str;
}
}
I try to pass an instance:
SafeString name;
To a function:
FrameInput(std::string& name);
But the compiler is unable to distinguish the implicit conversion.
When I change the variable and function signature, adding const, the compiler passes.
const SafeString name;
const FrameInput(std::string& name);
What changes do I have to do in the SafeString class to support both const and non-const variables for const and non-const function parameter, respectively?