-3

I have a struct that is declared in a C++ header file with the line:

struct AII_Common_Export message{
    ...
};

I am then trying to create an instance of that struct in a C++ source file, so that I can set/ use some of the attributes stored in the struct:

message data;

However, when I compile my code, I get an "undeclared identifier" error on this line... I have included the header file in the source file, so I don't understand why I am getting this error- can someone explain it to me?

I also tried creating the instance of it with:

AII_Common_Export message data;

But then got the compile error: "syntax error: missing ';' before identifier 'data'.

Any ideas how I can fix this, so that I can create an instance of the struct?

EDIT

I have just found the AII_Common_Export definition- it is defined with:

#    define AII_Common_Export ACE_Proper_Import_Flag

and the ACE_Proper_Import_Flag is defined with:

#define ACE_Proper_Import_Flag __declspec (dllimport)

These two definitions are in separate header files.

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
  • 2
    @AdrianoRepetti I presume that is a define for something else – Marco A. Nov 19 '14 at 11:25
  • @MarcoA. pretty right! soneone2088, did you include such header? – Adriano Repetti Nov 19 '14 at 11:25
  • @MarcoA. But this isn't a correct syntax anyway. – Korbi Nov 19 '14 at 11:27
  • @OP: Post the code that defines `AII_Common_Export`. @Korbi I didn't say that's correct, I just guessed – Marco A. Nov 19 '14 at 11:27
  • @MarcoA. After "struct" must be the name of the struct. Not more no less, i guess. – Korbi Nov 19 '14 at 11:30
  • Yes, as mentioned in my OP, I have included the header file... – Noble-Surfer Nov 19 '14 at 11:31
  • The header file was not written by me, and is currently being used in other cpp files, so the struct definition is correct. I'm just not sure whether I am using it correctly...? – Noble-Surfer Nov 19 '14 at 11:32
  • 1
    @Korbi: This is incorrect. It's not standard C++, but a lot of compilers place export directives between struct/class and the name. You commonly use a macro to hide the differences or for redefining it when importing it. You'd expect a #define AII_Common_Export __declspec(dllexport) or some kind of equivalent somewhere - OP just needs to make sure that define is visible too – ltjax Nov 19 '14 at 11:50
  • @ltjax Wow. I didn't hear of this before. Sorry. – Korbi Nov 19 '14 at 11:52
  • @Itjax, thanks for your comment, I have just found those definitions, and added them to the OP. – Noble-Surfer Nov 19 '14 at 11:57

1 Answers1

2

Just do.

 struct message{
        ...
    };

message data;

see http://www.cplusplus.com/doc/tutorial/structures/

Korbi
  • 714
  • 1
  • 9
  • 18
  • That is exactly what I have done- as mentioned in my OP, the struct is defined in the header with: `struct message{...};`, and I am creating an instance of it in the cpp with: `message data;`, but I'm getting this error... – Noble-Surfer Nov 19 '14 at 11:30
  • 2
    you did" struct AII_Common_Export message{ ... };" Thats not correct. You have to remove "message" or "AII_Common_Export". – Korbi Nov 19 '14 at 11:31
  • I didn't write the header file- it was written by someone else, and is currently being used by other cpp files, so I must assume the definition of the struct is correct as it stands... – Noble-Surfer Nov 19 '14 at 11:35
  • 2
    In that case you are missing another header which defines `All_Common_export`. – Tom Nov 19 '14 at 11:52
  • I have included the header file in which `AII_Common_export` is defined, but am now getting an error which says "use of undefined type 'message'".... – Noble-Surfer Nov 19 '14 at 12:10