MSVC16.9.2 Unable to recognize header file.

slipbits 16 Reputation points
2021-03-21T22:53:51.517+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,101 Reputation points Microsoft Vendor
    2021-03-22T03:25:04.1+00:00

    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.

    0 comments No comments

  2. Sam of Simple Samples 5,516 Reputation points
    2021-03-22T03:37:24.77+00:00

    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?

    0 comments No comments