Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C++;?_C++ - Fatal编程技术网

C++ 如何在C++;?

C++ 如何在C++;?,c++,C++,我有以下课程 class Node { int key; Node**Nptr; public: Node(int maxsize,int k); }; Node::Node(int maxsize,int k) { //here i want to dynamically allocate the array of pointers of maxsize key=k; } 请告诉我如何在构造函数中动态分配指针数组——该数组的大小为maxsize Node:

我有以下课程

class Node
{
    int key;
    Node**Nptr;
public:
    Node(int maxsize,int k);
};
Node::Node(int maxsize,int k)
{
   //here i want to dynamically allocate the array of pointers of maxsize
   key=k;
}
请告诉我如何在构造函数中动态分配指针数组——该数组的大小为maxsize

Node::Node(int maxsize,int k)
{
   NPtr = new Node*[maxsize];
}

但像往常一样,使用std::指针向量可能更好。

这将是
Nptr=newnode*[maxsize]
另外,记住在析构函数中使用
delete[]

假设要创建3行4列的矩阵

int **arr = new int * [3];  //first allocate array of row pointers

for(int i=0 ; i<rows ; ++i)
{
   arr[i] = new int[4]; // allocate memory for columns in each row
}
int**arr=newint*[3]//首先分配行指针数组

对于(int i=0;iWhy是在int之后而不是在第一行之前添加的*?