我已經分配的對象數組作爲: int numPlwDistanceClimb = 5;
int numFl = 6;
GRBVar** t_gd = 0;
t_gd = new GRBVar* [numFl];
GRBVar* x = 0;
x = model.addVars(numFl, GRB_CONTINUOUS);
for (int k = 0; k < numFl; k++)
上how new works in C++閱讀了我嘗試以下的代碼: #include <iostream>
using namespace std;
struct A { int m; }; // POD
int main()
{
A* a = new A;
cout<<"A m="<<a->m<<endl;
return 0;
}
而輸出總是 「A
我碰到這個問題,它創建了3塊內存,我很迷惑如果刪除* r,** r仍然存在與否?我應該將**移到* r的位置嗎? 我是否需要另一個「新的int」語句來賦值? int t = 5;
int **r;
r = new int *; //declare pointer
*r = new int;
delete *r; // delete pointer
*r = t; //give ne