[xsd-users] template<typename C> type_(const C*) constructor
creates unexpected empty copies of any pointer
Oliver Schneider
xsd-users at oli-obk.de
Fri Sep 19 04:05:35 EDT 2014
Hi Boris,
i have a list of idrefs:
<sometype>
<myref>ID1</myref>
<myref>ID2</myref>
</sometype>
then i loop over them:
for (auto id : myref()) {
id->dostuff();
}
correct would be
for (auto& id : myref()) {
id->dostuff();
}
as the former copies the object, the object has no reference to the root
of the structure, and can therefor not find the item it points to.
I'm actually not sure which constructor is invoked, even if the copy
constructor is disabled this copying still happens. Maybe the element is
cast to string and then the string constructor is invoked?
/Oliver
Am 19.09.2014 09:51, schrieb Boris Kolpackov:
> Hi Oliver,
>
> Oliver Schneider <xsd-users at oli-obk.de> writes:
>
>> I ran into another situation of the same kind.
>> The idref class has constructors that'll happily take strings, char* and
>> some others as arguments. It's really easy to accidentally use them.
>
> Hm, I am not sure about this one. idref is a string. Here is a quote
> from the documentation:
>
> The idref class publicly inherits from and has the same set
> of constructors as std::basic_string. It therefore can be
> used as std::string [...]
>
> Can you show some concrete examples where you found this dangerous.
>
> Boris
>
More information about the xsd-users
mailing list