class AdaFruitPWM8 : public Device
{
public:
AdaFruitPWM8(char *in_name, int in_dependent_device_id);
~AdaFruitPWM8(); // destructor
typedef struct {
int pwm[4]; // - for each events, value of pwm
int initColor;
int currentColor;
int pin;
long colorStartTime;
} colorAux;
colorAux color[8];
}
When I cleanup, delete the class object, do I need to clean up the struct instances as well, like
AdaFruitPWM8::~AdaFruitPWM8() {
//clean up
//need clean up the struct?
color[8] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
}
When I cleanup, delete the class object, do I need to clean up the struct instances as well, like
Assigning different values does NOT "clean up" an instance of a struct. You could add a destructor to the struct, and delete anything that needed deleting when the struct instance goes out of scope. Since you don't actually have anything that needs deleting, doing so would be a waste of time.
Thanks. Just making sure. I believe the struct instances are in automatic memory. When the class instance is deleted, I guess the structs are automatically dealt with.
In C++ there is no "automatic memory". There are "automatic variables". Maybe you are conflating the two.
In any case, in your example, there is no "automatic" anything. color is just another normal member of AdaFruitPWM8. In terms of lifetime color is no different than a simple int member. When AdaFruitPWM8 instances are created the memory for color is included in the block of memory for that instance. When an instance is destroyed the entire block is freed, which includes color.