[xsd-users] template<typename C> type_(const C*) constructor creates unexpected empty copies of any pointer

Boris Kolpackov boris at codesynthesis.com
Tue Sep 23 01:50:27 EDT 2014


Hi Oliver,

Oliver Schneider <xsd-users at oli-obk.de> writes:

> while true, isn't the purpose of the type and class system to prevent
> accidents like this?

Yes, but the type system cannot prevent every incorrect use case.


> A copied idref object is not really of much use. You can only use it to
> print the idref or to manually get the target through the root object.
> Since it's unlikely that someone wishes to copy an idref, it should be
> explicit, not implicit in my oppinion.

Idref's are copied all the time. Remember, it has a dual interface, that
of a string (according to XML Schema) and of a kind-of-smart-pointer. You
still need to initialize it with ID before it can be used as a smart
pointer:

idref id ("PERSON-1234");
person (id, "John", "Doe");

But if you don't need this functionality, there is good news: customize
idref and make it non-copyable. I am not sure the generated code will
work; but I think it will, just keep _clone().

Boris



More information about the xsd-users mailing list