malloc is a C function - it should not be used with C ++ objects, which is very well explained here (short answer: in C ++, when you are not related to POD , std::list in your case, you should call the constructor of the object so that it is ready to use, and malloc() does not).
Instead, use new . While malloc only allocates a vertex sized memory block, new does this, and also initializes std::list and also calls its constructor (it is interesting to note that when you call delete() , you call your descriptor object).
Here is a snippet of code that works for your case, although I suggest you start using more C ++ features in C ++ projects:
#include <iostream>
source share