P
petertwocakes
Hi
class StringSubClass : public string {
public:
StringSubClass();
StringSubClass(const char* v) : string(v) {} // casting constructor
virtual ~StringSubClass(){};
StringSubClass& operator=(const string& str) { return
(StringSubClass&)this->assign(str); }
};
If I don't have the casting constructor, then
StringSubClass str = "abc";
fails;
If I don't have the operator=, then
StringSubClass str;
str = "abc";
fails;
But, if I have them both I get the error:
ambiguous overload for 'operator=' in 'sub = "abc"'
How can I define it such that all of the following work?
StringSubClass subStr = "abc";
subStr = "abc";
string stdStr;
StringSubClass subStr2 = stdStr;
subStr2 = stdStr;
I've tried many permutations, but at least one always fails for either
having no definition, or ambiguous overload.
Thanks
class StringSubClass : public string {
public:
StringSubClass();
StringSubClass(const char* v) : string(v) {} // casting constructor
virtual ~StringSubClass(){};
StringSubClass& operator=(const string& str) { return
(StringSubClass&)this->assign(str); }
};
If I don't have the casting constructor, then
StringSubClass str = "abc";
fails;
If I don't have the operator=, then
StringSubClass str;
str = "abc";
fails;
But, if I have them both I get the error:
ambiguous overload for 'operator=' in 'sub = "abc"'
How can I define it such that all of the following work?
StringSubClass subStr = "abc";
subStr = "abc";
string stdStr;
StringSubClass subStr2 = stdStr;
subStr2 = stdStr;
I've tried many permutations, but at least one always fails for either
having no definition, or ambiguous overload.
Thanks