我有这个代码:
Derived **args = new Derived*[2];
args[0] = new Derived();
args[0]->setname("BLABLA \n");
cout << args[0]->getname();
delete args[0];
args[1] = new Derived();
args[1]->setname("BLABLABLA\n");
cout << args[1]->getname();
delete args[1];
delete [] args;
是delete [] args
必需的吗?为什么?
另外,Derived **args = new Derived*[2]
真正的作用是什么?它是否为两个指针分配空间Derived
?如果是这样,那么如何在堆上动态创建一个包含 2 个 Derived 类型的对象的数组?