gln
gln

Reputation: 1031

C++ Error C2061 - typdef definition

In my c++ application I have aaa.h file which has this definition in it:

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

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

in my aaa.cpp I write:

#include "aaa.h"

DDD * dddPtr

but then I got this error: Error c2061: syntax error: identifier 'DDD'

can you please help with this issue?

thanks

Upvotes: 0

Views: 961

Answers (2)

blackbird
blackbird

Reputation: 967

First thing: you should terminate the declaration with a semicolon ;.

Second: In your case, there is no need for typedefs in C++, just define classes or structures:

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.

Upvotes: 1

Roger Rowland
Roger Rowland

Reputation: 26279

For C++ you don't need that typedef'ed struct - just do this:

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;

Upvotes: 1

Related Questions