0

I have a type defined in C++ the following way:

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;
};

I was thinking to overload the assignment operator like this:

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

Is this allowed and useful approach or are there any side effects?

Patryk
  • 22,602
  • 44
  • 128
  • 244
Simon
  • 1,616
  • 2
  • 17
  • 39

0 Answers0