Linked Questions

Popular Questions

I have a simple C++ calculator with three classes (just for practice, I wouldn't actually need that many). They are Calculator (the main Object that uses the others) Expression (a simple data structure for storing to integers and an enum instance) and Parser (which reads in an input from the user and converts into an expression). Here's the code for the Calculator class header file:

#ifndef CALCULATOR_H
#define CALCULATOR_H

#include <Expression.h>

class Calculator
{
public:
    enum Operation {Addition, Subtraction, Multiplication, Division, InvalidOperation};

    Calculator();
    ~Calculator();

    float calculate (const char* text);
protected:

private:
    float calculate (Operation o, float num1, float num2);
    float calculate (Expression* e);
};

#endif

and the Expression header file:

#ifndef EXPRESSION_H
#define EXPRESSION_H

#include <Calculator.h>

class Expression
{
public:
    Expression(Calculator::Operation operand, float num1, float num2);
    virtual ~Expression();

    Calculator::Operation getOperand ();
    float getNum1 ();
    float getNum2 ();
protected:

private:
    Calculator::Operation _operand;
    float _num1;
    float _num2;
};

#endif // EXPRESSION_H

The compiler tells me that in the constructor of the Expression class that 'Calculator' has not been declared even though I'm only trying to access the enum, not an instance of calculator (and if I were there would be no reason why it shouldn't work. If you have any idea what could have caused this problem please let me know.

Thanks in advance!

Edit: I actually tried removing the ::Operation part and that didn't work either so this problem isn't limited to enums.

Related Questions