One possible option:
struct BaseReplayFrame {
int frame_type;
BaseReplayFrame(int ft ) {
frame_type = ft;
}
};
struct ReplayFrame_8 : public BaseReplayFrame {
float data[116];
ReplayFrame_8() : BaseReplyFrame(8) {
//...
}
};
struct ReplayFrame : public BaseReplayFrame {
double time;
float data[212];
ReplayFrame():BaseReplayFrame(0): {
}
};
Then, you can declare your vector as
std::vector<unique_ptr<BaseReplayFrame>> frames;
and insert there frames created via new, something like
frames.push_back(new ReplayFrame_8());
(see Why can I not push_back a unique_ptr into a vector? for details on pushing unique_ptr's into vectors, but here it doesn't seem to be necessary).
If you don't want to have frame_type within your BaseReplayFrame - it should be also possible via having vector element type as something like
pair<int,unique_ptr<BaseReplayFrame>>
, though it will be probably more cumbersome.
EDIT: a better option if having non-empty BaseReplayFrame is ok:
struct BaseReplayFrame {
virtual float* get_data() = 0;
virtual size_t get_data_size() = 0;
};
struct ReplayFrame_8 : public BaseReplayFrame {
float data[116];
virtual float* get_data() { return data; }
virtual size_t get_data_size() { return 116; }
};
struct ReplayFrame : public BaseReplayFrame {
double time;
float data[212];
virtual float* get_data() { return data; }
virtual size_t get_data_size() { return 212; }
};
frames is declared as above, and data can be accessed without cast, via
size_t datasz = frames[i]->get_data_size();
float* data = frames[i]->get_data();
Access to time can be added in a similar manner.