我正在尝试使用指向结构的双指针。构建成功,但运行时出现以下错误:
Run-Time Check Failure #3 - The variable 'test2' is being used without being initialized.
代码是:
testStructure* test1 = (testStructure*)malloc(sizeof(testStructure));
testStructure** test2 ;
test1->Integer = 1;
test1->Double = 4.566;
*test2 = test1;
结构是:
typedef struct{
int Integer;
double Double;
} testStructure;
我哪里出错了?
最佳答案
*test2 = test1; // test2 is pointing no where to get dereferenced.
必须
test2 = &test1;
关于c++ - 指向结构体的双指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9231284/