简体   繁体   中英

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. In this case it will point to 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)->...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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