c++ - 指向结构体的双指针

标签 c++ c

我正在尝试使用指向结构的双指针。构建成功,但运行时出现以下错误:

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/

相关文章:

C 并发程序(连载)

c++ - CMake Boost 链接问题

c++ - 在 C++ 中将结构数组展平为多个数组

c - 如何在没有填充位的情况下用 C 语言输出二进制文件

仅使用一个信号量的生产者-消费者 C 解决方案

c++ - 为什么 m_zh = Zookeeper_init( m_zkUrl.c_str(), NULL, 10000, 0, NULL, 0 ) 会导致内存泄漏?

c++ - 在 C++17 中调用对象生命周期之外的非静态成员函数

c++ - 在 C++ 中使用 STL 实现图形和树的良好且稳定的方法是什么?

c++ - 将图片从excel复制到剪贴板->在程序中输出->得到平滑的图片。失败在哪里?

c# - 如何从 C# 调用具有 void* 回调和对象参数的 C++ Dll 中的函数