我在弄清楚复制指针的语法时遇到麻烦。
我将如何制作theVar2=theVar
?
Struct MyStructureType {
double* theVar2;
}
MyStructureType* myStruct;
double* theVar;
theVar = malloc(sizeof(double));
myStruct->theVar2 = theVar; //segfaults
最佳答案
拳头为MyStructureType
分配内存,然后在其中使用data member
。
MyStructureType* myStruct = new MyStructureType();
double* theVar = new double();
myStruct->theVar2 = theVar;