简体   繁体   中英

typedef of nested structs

I'm trying to typedef a group of nested structs using this:

struct _A
{
    struct _Sim
    {
        struct _In
        {
            STDSTRING UserName;
            VARIANT Expression;
            int Period;
            bool AutoRun;
            //bool bAutoSave;
        } In;

        struct _Out
        {
            int Return;
        } Out;

    } Sim;

} A;

typedef _A._Sim._In SIM_IN;

The thing is the editor in VS2010 likes it. It recognizes the elements in the typedef, I can include it as parameters to functions but when you go to build it I get warnings first C4091 (ignored on left when no variable is declared) and then that leads to error C2143 "missing ';' before '.'.

The idea of the typedef is to make managing type definitions (in pointers, prototypes, etc) to _A._Sim._In easy with one name...a seemingly perfect use for typedef if the compiler allowed it.

How can I refer to the nested structure with one name to make pointer management and type specifiction easier than using the entire nested name (_A._Sim._In) ?

It might not be preferable to do so but, if it cannot be achieved using a typedef, I guess you could always do

#define _A._Sim._In SIM_IN

But as I said you might not prefer that for various reasons. :)

The dot operator is a postfix operator applied to an object (in terms of C). Ie, you can not apply it to a type.

To reach what you want you can use a function or a macro, eg:

 #define SIM_IN(x) x._Sim._In

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