I hope someone might be able to answer why the following doesn\'t work. Bear with me though, I am still very much a noob... I just cannot get to the bottom of why the follow
What the error is trying to explain is that your assignment "s = t
", where s
is a std::string
, would be valid if t
were a std::string
too, or if t
were a [const
] char*
. Your conversion operators can convert a t
into either, so the compiler has no basis on which to choose one over the other....
You can disambiguate this explicitly by selecting the conversion you want:
s = t.operator std::string();
s = static_cast(t);
Or you can provide only one of the conversions and let the user do a further conversion when necessary.
You may find though - in the end - that any conversion operator is more trouble than it's worth... it's telling that std::string
itself doesn't provide a conversion operator to const char*
.