Attribute of a struct receiving multiple structs

Asked

Viewed 106 times

0

It is possible an attribute of a struct receive several structs?

For example, I need the attribute LPWFSPINFDK lppFDKs; that is part of the struct _wfs_pin_func_key_detail, receive multiple structs _wfs_pin_fdk.

I am trying this way, compiles, but the final program does not recognize:

    WFSPINFUNCKEYDETAIL PinFunKeyDetail;

    WFSPINFDK ObjPinKey;
    LPWFSPINFDK PinKey;
    PinKey = &ObjPinKey;

    PinKey->ulFDK = WFS_PIN_FK_FDK01;
    PinKey->usXPosition = 5;
    PinKey->usYPosition = 5;

    PinFunKeyDetail.lppFDKs = &PinKey;

STRUCT: _wfs_pin_fdk

typedef struct _wfs_pin_fdk
{
    ULONG               ulFDK;
    USHORT              usXPosition;
    USHORT              usYPosition;
} WFSPINFDK, * LPWFSPINFDK;

STRUCT: _wfs_pin_func_key_detail

typedef struct _wfs_pin_func_key_detail
{
    ULONG               ulFuncMask;
    USHORT              usNumberFDKs;
    LPWFSPINFDK       * lppFDKs; //Aqui recebo as structs
} WFSPINFUNCKEYDETAIL, * LPWFSPINFUNCKEYDETAIL;

1 answer

0

Respondent: It is possible an attribute of a struct receive several structs. The attribute you refer to, however, is only a pointer, not a container. Pointers cannot receive several structs, only addresses of these.

Something that can receive several structs would be a std::vector<_wfs_pin_fdk>.


By the posted passages, LPWFSPINFDK is a type defined as pointer to _wfs_pin_fdk.

In class _wfs_pin_func_key_detail, the attribute lppFDKs is a pointer to LPWFSPINFDK.

That is to say: lppFDKs is a pointer to pointer of _wfs_pin_fdk.

Maybe you forgot to set usNumberFDKs ? Inferring from the variable name, it seems to keep how many pointers to _wfs_pin_fdk are stored in lppFDKs.

Changing your example so that lppFDKs point to an array of multiple pointers:

WFSPINFUNCKEYDETAIL PinFunKeyDetail;

//três _wfs_pin_fdk
WFSPINFDK PinKeyA;
WFSPINFDK PinKeyB;
WFSPINFDK PinKeyC;

//(..algum código manipulado os _wfs_pin_fdk..)

//endereço dos três _wfs_pin_fdk , em array
LPWFSPINFDK PinKeys[3] = {
    &PinKeyA,
    &PinKeyB,
    &PinKeyC
};

//passa para lppFDKs o endereço da array de LPWFSPINFDK
PinFunKeyDetail.lppFDKs = PinKeys;

//palpite: esse atributo indica quandos elementos são apontados por lppFDKs 
PinFunKeyDetail.usNumberFDKs = 3;

You said that

the final programme does not recognise

But that’s very vague, I don’t know what program you’re referring to. Here is the online code, compiling on Ideone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.