简体   繁体   English

取消引用将指向结构的空指针

[英]Dereferencing Void Pointer that will point to a structure

I have the following structures: 我有以下结构:

typedef struct TTCAPMessage {
        uint8_t packagetype; //{should be Query /w Permission or Response}
        uint32_t transid; //{transaction ID number}
        std::vector<TTCAPComponent_t> components; //{a string of component Information elements}
        bool parseok; //{false if error occured}
} TTCAPMessage_t;

typedef struct TTCAPComponent {
        uint8_t componenttype; //{should be Invoke, Return Result, Reject, etc.}
        uint8_t componentid; //{component ID code}
        uint8_t operationcode; //Query operation code, "Private TCAP"
        void* pParameterSet;
} TTCAPComponent_t;

typedef struct myStruct {
      .....
} mySruct_t;

In TTCAPComponent_t, there is a void * that is supposed to point to two different types of structures. 在TTCAPComponent_t中,有一个空*应该指向两种不同类型的结构。 In this case it will point to myStruct_t. 在这种情况下,它将指向myStruct_t。 I want to retrieve the data within it. 我想检索其中的数据。

So to dereference I've tried many variations of the following with no luck: 因此,为了取消引用,我尝试了以下多种变体,但没有运气:

tcapMessage->components[0]->(myStruct_t*)pParameterSet->(Accessing Structure data) ....

I've tried finding resources online but for some reason I cannot get this to work. 我尝试过在线查找资源,但是由于某种原因,我无法使它正常工作。 Thanks in advance for your help! 在此先感谢您的帮助!

The arrow -> operator only accepts a member name as its right-hand side, so you can't place a cast there. 箭头->运算符仅接受成员名称作为其右侧,因此您不能在其中放置演员表。 You're looking for the following syntax: 您正在寻找以下语法:

((struct myStruct_t*)tcapMessage->components[0]->pParameterSet)->...

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

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