I have the following structure:
struct node{
char name;
vector<node*> children;
void addChild(char name){
node *newChild = (node*)malloc(sizeof(node));
newChild->name = name;
children.push_back(newChild);
}
};
The code above compiles but crashes with a std::bad_alloc prompt whenever addChild is called for any node that was created using addChild.
It seems to me like i should somehow be allocating memory for the vector as well, but i am unsure about how i would go about doing that.
I am a "begginer" and know very little about memory allocation so any help would be appreciated.
Thanks in advance.