Original Post
I've got RTTI enabled, but it seems to be giving me trouble. I have a particular reason for not wanting to do it as a templated class, but the trouble is, if I create an object list using init, then try and access anything in it, I am required to cast the array to (sub_obj*). This defeats the whole purpose, as these object lists are in an array with each element containing a different type. For instance if I... It will try and access into the array 6 * sizeof(object) instead of 6 * sizeof(sub_obj1), and it will crash trying to find the vftable in a misaligned position. On further inspection... Evaluates to false, confirming my suspicions that the system is not taking into account the additional size of the subclass. I'm baffled. Is there some way to get it to recognize the correct size of the object?
class object {
int param1;
int param2;
virtual void do_stuff();
}
class sub_obj1 : public object {
int param3;
}
class sub_obj2 : public object {
int param4;
}
class obj_list {
object *list;
int num;
template <class o_type> init(int num_objs) {
list = new o_type[num_objs];
num = num_objs;
}
}
obj_list mylist;
mylist.init<sub_obj1>(12);
my_list.list[6].do_stuff();
sizeof(my_list.list[0]) == sizeof(sub_obj1)