带字符串参数的重载赋值运算符

时间:2016-02-19 13:07:32

标签: c++ operator-overloading

我有一个用C ++定义的类型:

class MyTypeT
{
public:
    MyTypeT();
    virtual ~MyTypeT();

    /// Initialize from string
    bool fromString(const std::string &typeinfo);

    /// Write to string
    virtual std::string toString() const;

    /// Is instance empty (not initialized yet)
    bool empty() const;
};

我正在考虑像这样重载赋值运算符:

MyTypeT & MyTypeT::operator=(const std::string & rhs)
{
    fromString(rhs);
    return *this;
}

这是允许的有用方法还是有任何副作用?

0 个答案:

没有答案
相关问题