views:

60

answers:

2

Hello,

I have a little problem in my project. I have build static library(e.g. test.lib) . Included it into my binary project linker and included #include "test.h" into stdafx.h. But when binary starts to build, C error occurs on CSomeObject test:

"error C2146: syntax error : missing ';' before identifier 'test'".

What could be wrong? I have also included to my binary project CSomeObject.h? Also maybe someone could explain how compiler works with includes? Thnx in advance :)

A: 

Is your CSomeObject class missing a ";" at the end of the class declaration, i.e. after the final closing brace ("}") in the header file?

jon hanson
+3  A: 

It sounds like you're not including everything that needs to be included or you have a incorrectly formed class/struct declaration.

Sometimes this type of error is generated because an identifier right before test is something the compiler knows nothing about, so it's treating the statement with test as a declaration for that identifier instead of for test. Then when it sees test it's a syntax error.

So if you have the line:

CSomeObject test;

but the compiler doesn't know anything about CSomeObject, you'll get the error you're seeing.

You'll also see the problem with something like the following:

class CSomeObject {

    // ...

} // there's a missing semi-colon here

CSomeObject test;

because what's happening is that the second CSomeObject is an instance of class CSomeObject, and `test is a spurious syntax error.

To by syntactically correct, what that should look like is:

class CSomeObject {

    // ...

};  // note the semi-colon...

CSomeObject test;
Michael Burr