简体   繁体   English

C ++错误C2061 - typdef定义

[英]C++ Error C2061 - typdef definition

In my c++ application I have aaa.h file which has this definition in it: 在我的c ++应用程序中,我有一个aaa.h文件,其中包含以下定义:

typedef struct 
{
   int a;
   int b;
} CCC;

typedef struct _DDD
{
   unsigned int e;
   CCC cccArray[100];
} DDD;

in my aaa.cpp I write: 在我的aaa.cpp中我写道:

#include "aaa.h"

DDD * dddPtr

but then I got this error: Error c2061: syntax error: identifier 'DDD' 但后来我收到了这个错误:错误c2061:语法错误:标识符'DDD'

can you please help with this issue? 你能帮忙解决这个问题吗?

thanks 谢谢

For C++ you don't need that typedef 'ed struct - just do this: 对于C ++,你不需要那个typedef struct - 只需这样做:

struct CCC
{
   int a;
   int b;
};

struct DDD
{
   unsigned int e;
   CCC cccArray[100];
};

and this: 和这个:

#include "aaa.h"

DDD * dddPtr = NULL;    // or = new DDD;

First thing: you should terminate the declaration with a semicolon ; 第一件事:你应该用分号终止声明; .

Second: In your case, there is no need for typedef s in C++, just define class es or struct ures: 第二:在你的情况下,在C ++中不需要typedef ,只需定义class es或struct ures:

struct CCC
{
   int a;
   int b;
};

struct DDD
{
   unsigned int e;
   CCC cccArray[100];
};

int main()
{
    DDD * dddPtr;
}

EDIT: Moreover, you should make sure that each member is properly initialized by providing suitable constructors for CCC and DDD . 编辑:此外,您应该通过为CCCDDD提供合适的构造函数来确保每个成员都已正确初始化。

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

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