Bison and doesn't name a type error

bison, c++, linker

Solution

Include the header in your scanner file before you include `*.tab.h`

// scanner.l file

%{
#include "myheader.h" 
#include "yacc.tab.h"

// other C/C++ code

%}

// helper definitions

%%

// scanner rules 

%%

`%union` is defined in `yacc.tab.h` so when you compile you need to make sure the compiler sees your new type definitions before it process `yacc.tab.h`

Problem

I have the following files: CP.h ``` #ifndef CP_H_ #define CP_H_ class CP { public: enum Cardinalite {VIDE = '\0', PTINT = '?', AST = '*', PLUS = '+'}; CP(Cardinalite myCard); virtual ~CP(); private: Cardinalite card; }; #endif /* CP_H_ */ ``` And dtd.y ``` %{ using namespace std; #include <cstring> #include <cstdio> #include <cstdlib> #include "AnalyseurDTD/DtdDocument.h" #include "AnalyseurDTD/CP.h" void yyerror(char *msg); int yywrap(void); int yylex(void); DtdDocument * doc = new DtdDocument(); %} %union { char *s; DtdElement * dtdelt; CP *cpt; CP::Cardinalite card; } ``` And the following strange error: ``` AnalyseurDTD/dtd.y:20:2: error: ‘CP’ does not name a type AnalyseurDTD/dtd.y:21:2: error: ‘CP’ does not name a type ``` The stange thing is that if I put CP *cpt; after DtdDocument * doc = new DtdDocument(); I have no error :/

Original source