Answer to Forward declarations
This problem exploits the fact that the C++ compiler only examines one
source file at a time. By carefully organizing our source files and using
forward declarations of types, this allows us to define two different
variants of MyType. These are, however, incompatible with
each other.
The reason the compiler allows for this is that the data type definition
does not leave any traces to the linker other than the name of the data
type. Since the compiler does not see more than one declaration of the
type from each cpp-file, this will not generate an error.
If we would have included constructors or other member functions in our type, we would get a linker error regarding multiple definitions of symbols.
Comments
New comment
You can use GitHub flavored markdown here. Parsed by Parsedown, which does not support all of GitHub's features. For example, specifying the language of code listings is not supported.