3 ms·
> It's important to note that in C++ you can easily run into problems with what you're describing: structs (objects) with different sizes being put into a vecto
by alexeiz 9y ago
> It's important to note that in C++ you can easily run into problems with what you're describing: structs (objects) with different sizes being put into a vector.
Baloney. In C++ vector<any> or vector<variant> accomplish this task without any problems whatsoever.
- pcwalton 9y agoAnd you can do the same in Rust with Box<Any>. What Rust doesn't have is the object slicing gotcha, which is probably a language design mistake in C++.
- pjmlp 9y agoThat gotcha is yet another flaw inherited from copy-paste compatibility with C. structs being classes with public access by default, with default assignment operator behaving the same way as C code would expect.