The standard actually requires all compliant compilers to allow that syntax in 9.4 [class.static]/2:
A static member s of class X may be
referred to using the qualified-id
expression X::s; it is not necessary
to use the class member access syntax
(5.2.5) to refer to a static member. A
static member maybe referred to using
the class member access syntax, in
which case the object-expression is
evaluated.
Now, there are some things you can do to avoid the pitfall, in no particular order
- Convert them into free-functions disallowing the syntax
- Improve the naming convention:
createFromXml
to make more explicit that it is a factory method
- Convert the static method into a concrete method that will perform the operation in the object, and provide an external method factory that will reuse the code.
From a design point of view, the first option has the advantage of un-coupling the serialized formats from the class itself. Something
(by a better name), represents an object with properties and operations and all those OO things. But in many cases Something
is unrelated to the fact that it can be serialized for sending or storage in different formats.
Users of your Something
class that only want to work with XML don't need to even know that your object can be serialized to Json. Neither users of Json or XML should be affected if you later add a database persistence option to the class.