I have a std::unordered_map<char, Node*>
inside my custom structure.
I want to initialize it with an empty map
. Did I do something wrong?
I have tried 2 kinds of initialization, both of them give me same result.
The following statement:
newStructure->map = unordered_map<char, Node*>();
sometimes results in success and the size of this map is 0, which it should be. Most of the time, this would fail during the initialization, and the following error would be generated with no initialization of the map
:
malloc: pointer being freed was not allocated
This would give me extreme huge size of the initial std::unordered_map
. The size of the map could be 88029716824088
.
How can I correctly initialize an empty std::unordered_map
struct?
My structure is defined like this:
struct Node {
char letter;
unordered_map<char, Node*> next;
bool hasEnd;
static Node* init(char);
}
And, my initializer
is defined like this:
Node* Node::init(char letter) {
Node *newNode = (Node*) malloc(sizeof(Node));
newNode->letter = letter;
newNode->hasEnd = false;
return newNode;
};
Sometimes, the size of the next
would be very huge number.