我想在YACC文件中添加結構工會,但我發現這個錯誤:結構工會C++ YACC
"error : member 'Info YYSTYPE ::info' with constructor not allowed in union "
%{
#include <cstdio>
#include <iostream>
using namespace std;
extern "C" int yylex();
extern "C" int yyparse();
extern "C" FILE *yyin;
struct Info{ int intval; float floatval; string stringval ;int type; }
void yyerror(const char *s);
%}
%union {
int ival;
float fval;
char *sval;
struct Info info;
}
錯誤告訴你幾乎到底是什麼問題:C++不允許你在聯合中使用一個構造函數(非POD類型)。沒有什麼特別與yacc有關。 –
[...與構造函數不允許在聯合問題中可能重複](http://stackoverflow.com/questions/6014717/with-constructor-not-allowed-in-union-problem) – Schore