I have class with lots of conversion functions:
class Something {
public:
string toXml();
string toJson();
...
static Something fromXml(string); // factory
static Something fromJson(string); // factory
...
};
Because static functions can be called on instance, it is easy to write code like this:
Something sss;
... initializing sss ...
string xml1 = sss.toXml();
sss.fromXml(xml1); // does nothing
string xml2 = sss.toXml();
assert(xml1 == xml2); // always true
So I want to forbid calling fromXXX on objects, or at least make them do something different.
Is there a way to do this?