Here and below: this masking and stuff is a no-go imo. Why don't you simply add the Type to the Item, then you can simply do reinterpret_cast<Item*>(index.internalPointer) ?