I have a reset() function that goes through a bunch of data and resets it. One of these is a pointer to a custom class, let’s say Apple *a;
The Apple class has a vector<Seed *> object, and a method resetSeeds() to go through and reset them all.
If reset() is called before a is allocated, I don’t want resetSeeds to iterate over its Seed objects, since these aren’t allocated yet. How do I do this?
Set
ato NULL to begin with. Then, inreset(), only calla->resetSeeds()ifais not NULL:If you’re using C++11, switch out
NULLin favour ofnullptr.