需要知道是否会在堆栈中或堆上创建这样的3d矩阵,以及是否在堆栈上创建新的3d矩阵并正确初始化默认值(内存集)
class Matrix {
protected:
int n[9000][420]; // is stack or heap if VVV is pointer?
};
void main()
{
Matrix* t = new Matrix(); // created on heap
}
最佳答案
一切都取决于您如何创建父对象。
MyClass {
int n[10];
};
int main(...) {
MyClass *c1 = new MyClass; // everything allocated on heap,
// but c1 itself is automatic
MyClass c2; // everything allocated on stack
// ...
}
堆和堆栈当然是实现细节,但是在这种情况下,我认为可以指定。
关于c++ - 在堆栈或堆上创建的类成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9073022/