Instead of using C standard function malloc
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
you have to use operator new
In this case the compiler will call a constructor of class std::string
that to create data member str
Othewise object str of type std::string
will not be created and the program will chash.
Function malloc
simply allocates a raw memory of a requested size. It knows nothing about constructors of classes.