我想扩展std::string
一些功能,所以我从中得到了我String
的。为了使代码像String str = stdStr;
工作一样,我试图重载赋值运算符,但由于某种原因我的代码没有被调用。我该如何解决?
#include <string>
class String
:
public std::string
{
public:
/*
I do know that this constructor will solve the problem, but is it possible to use the operator?
String ( const std::string& stdString )
{
...
}
*/
String& operator= ( const std::string& stdString )
{
...
return *this;
}
};
int main()
{
std::string foo = "foo";
String bar = foo;
return 1;
}