2013/9/15 Markus Engel <p637777@...1081...>:
Actually, this doesn’t work.
SPItem *item=SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr));
expanded: SPItem *item=((dynamic_cast<const SPItem*>((SPObject*)desktop->currentLayer()->appendChildRepr(this->repr)) != 0) ? (SPItem*)desktop->currentLayer()->appendChildRepr(this->repr) : 0)
This will call appendChildRepr twice and finally fail in an assertion, because the repr got modified.
Seems like finding a working solution isn’t that easy ;) .
What Johan's code does is equivalent to:
#define SP_TYPE(x) (dynamic_cast<SPType*>(reinterpret_cast<SPObject*>(x)))
or as a function:
inline SPItem *SP_TYPE(void *x) { return dynamic_cast<SPType*>(reinterpret_cast<SPObject*>(x)); }
There could also be a const variant, but I'm not sure whether it's needed anywhere:
inline SPItem const *SP_TYPE(void const *x) { return dynamic_cast<SPType const*>(reinterpret_cast<SPObject const*>(x)); }
Regards, Krzysztof