小编Cam*_*ler的帖子

如果`new int` 返回一个`int*`,那么为什么`new int[n]` 不返回一个`int**`?

我很疑惑怎么都new intnew int[n]返回int*。为什么后者不返回一个int**

以下是一些上下文:请参阅dataGoodrich、Tamassia 和 Mount 的第二版中的一个片段中的以下变量。C++ 教科书中的数据结构和算法:

class Vect {
   public:
      Vect(int n);
       ~Vect();
      // ... other public members omitted
   private:
      int* data;
      int size;
};
    
Vect::Vect(int n) {
    size = n;
    data = new int[n];
}
    
Vect::~Vect() {
    delete [] data;
}
Run Code Online (Sandbox Code Playgroud)

c++ free pointers memory-management heap-memory

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

标签 统计

c++ ×1

free ×1

heap-memory ×1

memory-management ×1

pointers ×1