3 ms·
I didn't say they were dynamically sized. You could either have objects of the same type, but with virtual functions, or you could make a union of all applicabl
by fgsfdsfgsfds 11y ago
I didn't say they were dynamically sized. You could either have objects of the same type, but with virtual functions, or you could make a union of all applicable objects (thus guaranteed to be constant sized, at the size of the largest object) and store those in the array/vector, switching on a type enum or calling a function from an inherited base class.
- haberman 11y ago> You could either have objects of the same type, but with virtual functions If objects have the same type, which is statically known, there is no need for virtual functions because the compiler can resolve the specific method implementation at compile-time. > or you could make a union of all applicable objects (thus guaranteed to be constant sized, at the size of the largest object) and store those in the array/vector, switching on a type enum You can do this in both C++ and Rust easily, with equivalent efficiency in both. In Rust you would just use an enum type. This design is generally highly discouraged though, because it requires callers to be aware of all possible "derived classes". My comments were only about the case where you are using true language-level polymorphism.