I always have thought of a struct as a fixed sized object and while there doesn’t seem to be any glaring compiler errors, I was wondering if doing this is generally in good practice. Would changing the struct to a class be more advisable or will a struct do just as well?
The code, just because people get fussy:
struct Sprite
{
float x;
float y;
std::vector<Sprite> sprite;
}
The essence of what I am doing is having children of a class as the same type as the parent. When the parent dies, the children do too.
An
std::vectorhas a specific known size, and any class or struct that contains it has a specific known size.std::vectorallocates memory on the heap to act as a variable sized array and stores a pointer to said memory. The only difference between a struct and a class is that a struct is defaultly public, and a class is defaultly private.