question

slipbits-2359 avatar image
0 Votes"
slipbits-2359 asked ·

MSVC16.9.2 Unable to recognize header file.

Unable to create or use a class variable from an #include header file. The code is:

 # include "header/Gawk.h"   // exists: I can "go to document"
    
 using namespace std;          // exists
 using namespace gawk;      // can't find,namespace (C2871)
    
 Gawk* g;                             // can't find class 'Gawk'(C2143)

I don't know why the Gawk.h header file is not recognized. Does it have to be in the same folder as this header file? Not recognizing the header file explains why Gawk* g isn't legal, but doesn't explain the C2143 error.

The C2871 error (can't find namespace) is because the Gawk.h header is not recognized.

The C2143 is a real head scratcher. The message is "syntax error: missing ';' before '*', which makes no syntactic sense.

I would like to create a pointer or reference to a class object in a header file, and then use this reference throughout the application. I would like to assign a value to this variable in an object separate from its definition. In this case, 'g' is defined in Global.h and assigned a value elsewhere and used throughout. Any idea how to do this?

c++
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered ·

Hi,

I don't know why the Gawk.h header file is not recognized. Does it have to be in the same folder as this header file?

What is the Gawk.h? I suggest you could try to add the path to the header file to the Additional Include Directories(property - >c/c++ -> General -> Additional Include Directories). And you could also try to add the absolute path where Gawk.h is located in the #include.

According to the Compiler Error C2143:

Because the compiler may report this error after it encounters the line that causes the problem, check several lines of code that precede the error.

I suggest you could try to solve the problem of unable to recognize header file, and then the later error may disappear.

Best Regards,

Jeanine Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SimpleSamples avatar image
0 Votes"
SimpleSamples answered ·

Are you sure? Are you sure that there is a namespace with the name gawk? Maybe it is Gawk, not gawk. And are you sure the class is Gawk, not gawk? Probably the class is Gawk but if the namespace is also Gawk then fixing the namespace name might fix everything.

If that does not help then can you post the lines in Gawk.h that define the namespace and class?

And what does exists: I can "go to document" mean? does it mean that you can right-click on the header in VS and then the file opens? If so then I do not understand the part where you say the header is not recognized. Can you clarify?





·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.