I\'ve made the example in Java but I think (not tested) that it works in other (all?) languages.
You have 2 files. First, M.java:
public
The first file doesn't need to know anything about XType except that it is a type, and similarly for MType in the second file. Also, in Java, all objects are effectively the same size (because everything is accessed through references), so the size of the object is not needed. This is not so in other languages - your code as it stands would not compile in C++, for example (language syntax apart).