extern declaration error
Given the following ...
In A.CPP:
1 2 3 4 5 6 7 8 9 10 11
|
typedef struct
{
char author_surname[64];
char author_forename[64];
char title[64];
char isbn[20];
char genre[MAXLENGTH+1];
ushort radBtnCategory;
} DialogData;
Dialogdata *addBookData;
|
// then add data to addBookData members i.e. addBookData->author_surname etc.
I want to reference addBookData's members in B.CPP but receive this error:
In B.CPP
extern DialogData *addBookData; <======= 'Declaration syntax error'
Guidance will be welcome!
Is the declaration of DialogData available to B.cpp?
helios: in what way?
I've tried putting
1 2 3 4 5 6 7 8 9
|
typedef struct
{
char author_surname[64];
char author_forename[64];
char title[64];
char isbn[20];
char genre[MAXLENGTH+1];
ushort radBtnCategory;
} DialogData;
|
in a header file and included that file in both A.CPP and B.CPP. That results in the same error but pointing at the A.CPP declaration
Dialogdata *addBookData;
I'm having a hard time seeing the problem. Post all three files (that is, the header, A.cpp, and B.cpp).
Helios:
Original :
A.CPP
1 2 3 4 5 6 7 8 9 10 11
|
typedef struct
{
char author_surname[64];
char author_forename[64];
char title[64];
char isbn[20];
char genre[MAXLENGTH+1];
ushort radBtnCategory;
} DialogData;
Dialogdata *addBookData;
|
B.CPP
extern DialogData *addBookData; <==== 'Declaration syntax error'
Revised:
HEADER.H
1 2 3 4 5 6 7 8 9
|
typedef struct
{
char author_surname[64];
char author_forename[64];
char title[64];
char isbn[20];
char genre[MAXLENGTH+1];
ushort radBtnCategory;
} DialogData;
|
A.CPP
1 2
|
#include "HEADER.H"
Dialogdata *addBookData; <==== 'Declaration syntax error'
|
B.CPP
1 2
|
#include "HEADER.H"
extern DialogData *addBookData;
|
Thx for looking at this.
I've resolved this as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
HEADER.H
typedef struct
{
char author_surname[64];
char author_forename[64];
char title[64];
char isbn[20];
char genre[MAXLENGTH+1];
ushort radBtnCategory;
} DialogData;
extern DialogData *addBookData;
|
1 2 3
|
B.CPP
DialogData *addBookData;
|
1 2 3
|
A.CPP
// no declaration of addBookData - the structure members are initialized in A.CPP
|
I have a successful compilation with this.
Last edited on
Topic archived. No new replies allowed.