Код: Выделить всё
struct Data {
// some fields
};
struct E : public virtual Data {
// some fields
};
struct A : public E {};
struct B : public E {};
struct EE : A, B {
E& a() {
return *static_cast(this);
}
E& b() {
return *static_cast(this);
}
};
Код: Выделить всё
int main() {
std::vector vec;
for (size_t i = 0; i < 10; ++i) {
auto ee = new EE(...);
vec.push_back(ee->a());
vec.push_back(ee->b());
}
// shuffle the `vec`
// your code may go here as well
for (size_t i = 0; i < 20; ++i) {
// your code goes here
}
// At this point All `EE` must be correctly `deleted`
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... references