繁体   English   中英

指向指针成员Struct的指针

[英]Pointer to pointer member Struct

它是我正在处理的代码的一部分。 当我尝试将Diagcb.end分配给ptr2 ,返回了错误。

我试图写成:

ptr2 = &Diagcb.end;
ptr2 = &diagcb->end;

但返回相同的错误。

typedef struct reportType {
    int a;
    int b;
    int c;
    int* ptr;
} reportType;

typedef struct cb {
    reportType* start;
    reportType* end;
    reportType arr[10];
}cb;
int fun (reportType* report);
main()
{
    cb Diagcb;
    reportType report;
    report.a = 0;
    report.b = 1;
    report.c = 2;
    report.ptr = NULL;
    reportType* ptr2;
    ptr2 = cb.end;
}

您应该将其写为ptr2 = Diagcb.end 因为Diagcd.end已经是一个指针,所以您不需要使用&来获取地址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM