小编Eva*_*van的帖子

使用std :: unique_ptr的双(二维)数组

我有一个指针分配给指针的双数组.

  // pointer to pointer
  int **x = new int *[5];   // allocation
  for (i=0; i<5; i++){
      x[i] = new int[2];
  }

  for (i=0; i<5; i++){      // assignment
      for (j=0; j<2; j++){
          x[i][j] = i+j;
      }
  }

  for (i=0; i<5; i++)   // deallocation
      delete x[i];
  delete x;
Run Code Online (Sandbox Code Playgroud)

我试图这样做unique_ptr:

std::unique_ptr<std::unique_ptr<int>[]> a(new std::unique_ptr<int>[5]);
  for (i=0; i<5; i++)
      a[i] = new int[2];
Run Code Online (Sandbox Code Playgroud)

但一直都是这样说的错误no operator = matches these operands.我在这做错了什么?

c++ unique-ptr c++11

10
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

c++11 ×1

unique-ptr ×1