Is it possible to push_back to a list of userClass a variable with different type?
list<MyClass*>* myList
list<int>* NewData
// -- ..some population of NewDat.. --
myList->push_back(NewData);
No. What you are asking for is not possible. myList
stores MyClass*
s, not int
s or lists of int
s. If you want a generic list, you can use std::list<std::any>
, or, in case you know the types in advance, std::list<std::variant<(types here)>>
.