小编use*_*026的帖子

如何在构造函数中将指针数组全部设置为nullptrs?

class TrieNode {
public:
    TrieNode() : next{new TrieNode *[26]} {}
    TrieNode **next;
    string word;
};
Run Code Online (Sandbox Code Playgroud)

我必须为此应用程序使用原始指针,我想知道如何nullptr在构造函数中设置所有 26 个指针?我是否必须循环next并单独设置每个人,还是有另一种更快的方法来做到这一点?

c++ arrays constructor pointers initialization

1
推荐指数
1
解决办法
63
查看次数

从自定义类型的 std::set 或 std::map 擦除需要 `operator==`?

当我从std::setstd::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)

c++ set

0
推荐指数
2
解决办法
67
查看次数

标签 统计

c++ ×2

arrays ×1

constructor ×1

initialization ×1

pointers ×1

set ×1