简体   繁体   English

嵌套结构的typedef

[英]typedef of nested structs

I'm trying to typedef a group of nested structs using this: 我正在尝试使用以下命令对一组嵌套结构进行typedef:

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. 事情是VS2010中的编辑器喜欢它。 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 ';' 它可以识别typedef中的元素,我可以将其包含为函数的参数,但是当您构建它时,我会首先收到警告C4091(在未声明任何变量的情况下忽略在左边),然后导致错误C2143“缺少';'” 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. typedef的想法是使用一个名称就可以轻松地管理_A._Sim._类型的类型定义(在指针,原型等中)……如果编译器允许的话,这似乎是typedef的完美用法。

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) ? 与使用整个嵌套名称(_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 这样做可能不是更可取,但是,如果使用typedef无法实现,我想您总是可以

#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). 点运算符是应用于对象 (用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

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

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