Danny
Danny

Reputation: 455

When adding the header file in the .cpp file, errors arise

The Nodes.h file alone when compiled works, however when I include it in the Nodes.cpp file, all the errors arise, such as missing type specifier - int assumed at line 11,12,13 . Also another error is syntax error: identifier 'ASTSimpleExpressionNode'. Is it something that I am doing wrong. Can't I specify how my struct can be constructed by defining the different constructors? For now the ASTSimpleExpressionNode is empty because if I continued the process it would duplicate all the errors.

Some of the errors:

Error C2535 'ASTExpressionNode::ASTExpressionNode(void)': member function already defined or declared [line 16] Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int [Line 11, 12,13 so on.] Error C2143 syntax error: missing ';' before '*' [Line 11,12,13] unexpected token(s) preceding ';' [Line 11,12,13]

Nodes.h file.

#pragma once
#include <string>
using namespace std;
struct ASTNode
{

};

struct ASTExpressionNode : ASTNode
{
    ASTSimpleExpressionNode *left;
    ASTRelationOperatorNode *rel_op;
    ASTSimpleExpressionNode *right;

    ASTExpressionNode(ASTSimpleExpressionNode *l);
    ASTExpressionNode(ASTSimpleExpressionNode *l, ASTRelationOperatorNode *op, ASTSimpleExpressionNode *r);
};

struct ASTSimpleExpressionNode : ASTExpressionNode
{

};

struct ASTRelationOperatorNode :ASTExpressionNode
{
    string rel_op;

    ASTRelationOperatorNode(string op);
};

Nodes.cpp file.

#include "Nodes.h"

Upvotes: 0

Views: 169

Answers (1)

rwols
rwols

Reputation: 3078

Forward-declare ASTSimpleExpressionNode and ASTRelationOperatorNode:

struct ASTSimpleExpressionNode;
struct ASTRelationOperatorNode;

struct ASTExpressionNode : ASTNode
{
   // etc

Upvotes: 1

Related Questions