I’ve written a class Tag that holds tags as strings and allows operations to be done on it. For ease of use I’m overloading the operator= for string-like types. What I’ve got so far:
Tag& Tag::operator=(const std::string& rhs)
{
setTag(rhs);
return *this;
}
Tag& Tag::operator=(const char* rhs)
{
setTag(rhs);
return *this;
}
(where setTag() is overloaded for std::string and char). Most of the usage is covered by this:
Tag tag1 = std::string("lala");
Tag tag2;
tag2 = std::string("lala2");
Tag tag3;
tag3 = "lala";
however, the most ‘fundamental’ one does not compute:
Tag tag4 = "lala";
It gives me this error:
conversion from 'const char [5]' to non-scalar type 'Tag' requested
How can I fix this? What am I doing wrong?
That last one isn’t an
operator=()– you need a constructor that takes achar const*.