0

Here is the code: globalfuncvars.h:

#ifndef GLOBALVARIABLES_H
#define GLOBALVARIABLES_H

#include <bits/stdc++.h>

#include "ast.h"
#include "commandline.h"

using namespace std;

extern int cnt;
extern int key_count, sep_count, opt_count, id_count, lit_count;

extern ast *parse_tree_root;

extern ast *ast_root;

#endif

ast.h:

#ifndef AST_H
#define AST_H

#include <bits//stdc++.h>
#include "globalfuncvars.h"

using namespace std;

class ast{
public:
    /* class definition */
};

#endif

The file ast.h uses the cnt variable from globalfuncvars.h. I want to include the globalfuncvars.h file in my main.cpp but upon compiling, I get the error:

./src/globalfuncvars.h:19:8: error: ‘ast’ does not name a type
   19 | extern ast *parse_tree_root;
      |        ^~~
./src/globalfuncvars.h:21:8: error: ‘ast’ does not name a type
   21 | extern ast *ast_root;

How do I fix this?

  • 3
    `globalfuncvars.h` does not need `#include "ast.h"`. Use a **forward declaration** instead. Never do this: `#include `. Never do this: `using namespace std;`. – Eljay Apr 13 '23 at 13:55
  • 1
    Also, separate class definitions (in headers) from member function definitions (not in headers) in the conventional manner. Also also, it's never too soon to stop using global variables. – molbdnilo Apr 13 '23 at 14:36

0 Answers0