I have a couple of classes derived from Element
. Each of them has a generate()
method that returns something. Also, I have a Rep
class that is derived from Element
, too.
I need to initialize a Rep
object with any of Element
children and be able to call generate()
.
#include <string>
#include <vector>
#include <iostream>
class Element{
};
class Any : public Element{
std::string text;
public:
Any(std::string text) : text(text) {};
char generate(); //returns random symbol
};
class Per : public Element{
std::string text;
public:
Per(std::string text) : text(text) {};
std::string generate();
};
class Format : public Element{
int format;
std::string text;
public:
Format(int format, std::string text) : format(format), text(text) {};
std::string generate();
};
class Rep : public Element{
int count;
Element action;
public:
Rep(int count, Element action) : count(count), action(action) {};
void generate(){
for(int i = 0; i<count; i++)
std::cout<<action.generate();
}
};
//i want to do this
int main(){
Rep a(10, Any("help"));
a.generate(); //eg. "ehplhppelh"
}