can you add different class objects to same list?
See boost::any.
You can use std::vector and then use it to add heterogeneous types into.
Example:
std::vector<boost::any> v;
v.push_back(std::string("hello world"));
v.push_back(42);
No, if they are unrelated objects. If they are related (i.e. have a common base class) then you can store the base class pointer (use smart pointers instead of raw pointers) in the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With