3 ms·
> If you have a class where this doesn't work (e.g. because it contains pointers into its own footprint) When would you have pointers to a classes own memory i
by heeen2 7y ago
> If you have a class where this doesn't work (e.g. because it contains pointers into its own footprint)
When would you have pointers to a classes own memory instead of a named class member for the same data?
- rhn_mk1 7y agoLinked lists, graphs. Granted, it's not the same structure, but it gets back there eventually.
- quietbritishjim 7y agoThis can happen if you have one class that contains a pointer or reference to another class, and then you create a helper class that instantiates both of them as direct member variables. Edit: Another example: Imagine you have a matrix class that contains a bit of memory as a char[] member to avoid heap allocation for small matrices. Then you maybe you want your data pointer to point directly at that data (rather than looking at a separate flag, which might cause an extra branch or just be more code complexity). I'm not saying it's a good idea, just it's obvious that it might come up.