0

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) ?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
brimaa
  • 169
  • 3
  • 11

2 Answers2

0

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. :)

Victor Zamanian
  • 3,100
  • 24
  • 31
0

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

To reach what you want you can use a function or a macro, e.g.:

 #define SIM_IN(x) x._Sim._In
Matthias
  • 8,018
  • 2
  • 27
  • 53
  • Thanks to everyone who responded. I think the issues with multiple included symbols and linkage issues are perhaps one of the most difficult aspects to understand about the C++ language because the behavior is unexpected and the causes are often subtle and difficult to determine. Even the textbooks that I've read don't do these issues justice yet they are critically important to understand to build any kind of program of reasonable size. One of the best sources of information on C++ I've fouund is the IBM documentation. – brimaa Mar 02 '13 at 06:19
  • http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr015.htm It's written clearly and succinctly and covers just about every rule for C++ and C. I'm using VS but this is my bible for understanding the rules for C++ at this time. – brimaa Mar 02 '13 at 06:23