我在弄清楚复制指针的语法时遇到了麻烦.
我该怎么做theVar2=theVar?
Struct MyStructureType {
double* theVar2;
}
MyStructureType* myStruct;
double* theVar;
theVar = malloc(sizeof(double));
myStruct->theVar2 = theVar; //segfaults
Run Code Online (Sandbox Code Playgroud)
拳头为内存分配MyStructureType,然后使用data member其中.
MyStructureType* myStruct = new MyStructureType();
double* theVar = new double();
myStruct->theVar2 = theVar;
Run Code Online (Sandbox Code Playgroud)