Why isn't this implementation of trie working?

I was trying to solve this problem.

My implementation of the trie is here

My problem is this: everytime I allocate new memory for a node, it seems to work fine. However, when I access the node using the array of pointers to them, it seems they are still nullptr.

What am I doing wrong?

The problem is the way you pass the node parameter during insertion. You pass the node by value, so the node you are operating on in the first recursion isn’t the root node, but rather a copy of it. So the modification doesn’t change the root node but the copy which is discarded at the end of the function. Passing by reference ( void insertR(std::string name, TrieNode & node) ) will work better. Alterntaively you can pass a pointer.