Reputation: 91
I have some code here:
#include <vector>
#include <cstdio>
class Syntax {
public:
Syntax();
~Syntax();
bool parseNext(int tokenID);
private:
struct Node {
int token;
std::vector<Node>* next;
} none, wS1, lParen1, wS2, sub1, add1, div1, mul1, wS3, intLit, wS4, rParen1, endL;
enum Tokens {
WHITESPACE,
ADD_OPERATOR,
SUB_OPERATOR,
MUL_OPERATOR,
DIV_OPERATOR,
L_PAREN,
R_PAREN,
INT_LITERAL,
NONE
};
none.token = NONE;
};
That is giving me the error:
parser.hpp:32:5: error: ‘none’ does not name a type
32 | none.token = NONE;
| ^~~~
In file included from parser.cpp:1:
parser.hpp:32:5: error: ‘none’ does not name a type
32 | none.token = NONE;
| ^~~~
I do not know why. I checked online examples and it seems to match perfectly. In fact, I copied a struct from an online example and received the same errors. Can someone please help.
Upvotes: 0
Views: 109
Reputation: 3775
You're trying to execute code in the body of your class, which isn't legal in C++. You need to put none.token = NONE;
inside the constructor.
Upvotes: 3