Hello
I have following struct
struct node {
std::string word
std::vector<struct node *> child;
}
When I create the new node, I have no way to initialize child vector.
What I essentially want is to check any element using operator[] is there is valid value.
I want to do following
if ( nodeptr->child[5] ) {
}
But Code crashes at if loop.
Is there other way to handle this.
In this case you would have to provide a constructor for you struct.
This will initialize the vector with 10
NULL-pointers. You can then check if an index isNULL(meaning it does not contain data), or not (it does contain data).