0

I'm trying to implement polymorphism, as can be seen by the code below. I want vector of expressions of type class expression. these expressions will have a right and left parameter object of type Parameter class. As it may have been guessed, this could recurse until one hits a string "a_string" or "an_id." However, the compiler doesn't, first of all, know what type "Expression" is for the vector. Any help is needed. Thank you.

#ifndef PARAMETER_H
#define PARAMETER_H
#include <string>
#include <vector>

using namespace std;

class Parameter
{

private:
    string a_string;
    string an_id;
    vector<Expression> expressions;



public:
    Parameter(bool expr_stringID);

};

class Expression : public Parameter
{
private:
    Parameter left_parameter;
    Parameter right_parameter;
    char op;

public:

};

#endif
user280339
  • 69
  • 1
  • 8

1 Answers1

2

Poymorphism either requires virtual functions (at least a virtual destructor), or the CRTP to realize Static Polymorphism.

You provide neither of these with your example.

Community
  • 1
  • 1
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190