class TrieNode {
public:
TrieNode() : next{new TrieNode *[26]} {}
TrieNode **next;
string word;
};
Run Code Online (Sandbox Code Playgroud)
我必须为此应用程序使用原始指针,我想知道如何nullptr
在构造函数中设置所有 26 个指针?我是否必须循环next
并单独设置每个人,还是有另一种更快的方法来做到这一点?
当我从std::set
或std::map
为自定义类型擦除时,例如,info
如果我使用https://en.cppreference.com/w/cpp/container/set/erase 中的(3) ,似乎我需要定义一个operator==
for info
。
但是,如果我有指向要删除的对象的迭代器,那么我相信我不需要operator==
并且可以使用链接中的 (2)。但是下面的代码似乎可以编译,所以我很困惑
struct info
{
info(int i, int j, int k) : i{i}, j{j}, k{k} {}
int i;
int j;
int k;
// bool operator==(const info&rhs)
// {
// return i == rhs.i && j == rhs.j && k == rhs.k;
// }
};
struct comparer_t
{
bool operator()(const info &lhs, const info &rhs) const
{
if(lhs.i == rhs.i)
{
if(lhs.j == rhs.j) …
Run Code Online (Sandbox Code Playgroud)