【发布时间】:2021-10-23 11:46:27
【问题描述】:
class TrieNode {
public:
TrieNode() : next{new TrieNode *[26]} {}
TrieNode **next;
string word;
};
我必须为此应用程序使用原始指针,我想知道如何在构造函数中将所有 26 个指针设置为 nullptr?我是否必须遍历next 并单独设置每个,还是有另一种更快的方法?
【问题讨论】:
-
这里不需要动态分配数组。
TrieNode *next[26]很好。std::array<TrieNode*, 26>更好。
标签: c++ arrays pointers constructor initialization