动态大小的类指针数组

Pio*_*cki -1 c++ arrays pointers class dynamic

那些是数组约束:数组有自定义大小,我将在程序顶部读取,这将是指向我自己的类Tree的指针数组,数组需要每个单元格的恒定读取时间.

这是我的代码不起作用: scanf("%d %d",&n,&q);
Tree *pointers = new Tree[n];
pointers[0]->value = NULL;

Ker*_* SB 5

scanf永远不要使用.在C++中,使用动态容器和iostream:

#include <iostreams>
#include <vector>

int main()
{
  unsigned int n;
  int q;

  if (!(std::cin >> n >> q)) { /* error! */ }

  std::vector<Tree> forest(n);

  // ...
}
Run Code Online (Sandbox Code Playgroud)

根据您的设置,最好先逐行读取然后处理每一行; 搜索这个网站,因为这已被回答了一百次.