I have a header file, General.h, that is the only header file for a
project that has three .cpp files. General.h has extern definitions for
many global variables and function prototypes.

General.h also has a single class definition.

When compiling I get this error

general.h(82) : error C2143: syntax error : missing ';' before '*'

when I have the following arrangement

extern CBitmapFile * pCBitmap_faces;

// other stuff

class CBitmapFile
{
// class contents defn?.
};

I do not get error C2143 if

extern CBitmapFile * pCBitmap_faces;

Comes after the class definition. I thought that extern meant that "I
promise I will define all after extern in due course."

Thanks.

Thomas

Re: extern and class by Carl

Carl
Sun Aug 17 10:30:36 CDT 2003

Thomas wrote:
> I have a header file, General.h, that is the only header file for a
> project that has three .cpp files. General.h has extern definitions
> for many global variables and function prototypes.
>
> General.h also has a single class definition.
>
> When compiling I get this error
>
> general.h(82) : error C2143: syntax error : missing ';' before '*'
>
> when I have the following arrangement
>
> extern CBitmapFile * pCBitmap_faces;
>
> // other stuff
>
> class CBitmapFile
> {
> // class contents defn?.
> };
>
> I do not get error C2143 if
>
> extern CBitmapFile * pCBitmap_faces;
>
> Comes after the class definition. I thought that extern meant that "I
> promise I will define all after extern in due course."

It does. The problem is that the class isn't even declared, let alone
defined, so the while the compiler understands that pCBitmap_faces will be
defined elsewhere, it doesn't know the type of that variable, since CBitmap
is undeclared at that point.

If you were to add

class CBitmapFile; // "forward declaration"

before the extern, then it would also compile without error.

-cd