I have the following in the main:
Sum *sum = new Sum(Identifier("aNum1"), Identifier("aNum2"));
And my classes are:
class Table {
private:
static map<string, int> m;
public:
static int lookup(string ident)
{
return m.find(ident)->second;
}
static void insert(string ident, int aValue)
{
m.insert(pair<string, int>(ident, aValue));
}
};
class Expression {
public:
virtual int const getValue() = 0;
};
class Identifier : Expression {
private:
string ident;
public:
Identifier(string _ident) { ident = _ident; }
int const getValue() { return Table::lookup(ident); }
};
class BinaryExpression : public Expression {
protected:
Expression *firstExp;
Expression *secondExp;
public:
BinaryExpression(Expression &_firstExp, Expression &_secondExp) {
firstExp = &_firstExp;
secondExp = &_secondExp;
}
};
class Sum : BinaryExpression {
public:
Sum(Expression &first, Expression &second) : BinaryExpression (first, second) {}
int const getValue()
{
return firstExp->getValue() + secondExp->getValue();
}
};
When I am compiling it I get the following error:
no matching function for call to 'Sum::Sum(Identifier, Identifier)'
candidates are: Sum::Sum(Expression&, Expression&)
The Identifier class is inheriting from Expression, so why am I getting this error?
You are privately inheriting Identifier from Expression change to: