2 ms·
Perhaps he should have put the textures in a central container and have the widgets use a reference to the texture item? I would think that adding textures as
by 72deluxe 11y ago
Perhaps he should have put the textures in a central container and have the widgets use a reference to the texture item?
I would think that adding textures as a child of the widgets would imply that he WANTED the textures copying. I wouldn't put child items into an object unless I wanted them copying too, as their lifetime is tied up with their parent object. The problem is not containers - it is more with his design and him wanting to control the lifetimes of child textures.
- _yosefk 11y agoWell, define "problem." Naive, correct C++ code will copy objects because it's the simplest way to make sure each object has one obvious owner and won't leak without having to write memory management code or fiddling with smart pointers, which have non-trivial semantics. Yeah, you can avoid the copying, but C++ definitely encourages it in the sense of making it the path of the least resistance.