Four classes (Variable, Function, Factor_Expression, and Float) derive from the class Factor.Code:Term::Term(const Term& t) { std::vector<Factor*> x = t.factors; if (x.empty()) return; Factor* f; for (std::vector<Factor*>::iterator i = x.begin();i != x.end();++i) { if ((*i)->who_am_i() == Factor::FLOATING) { f = new Float(*((Float*)(*i))); factors.push_back(f); } if ((*i)->who_am_i() == Factor::FACTOR_EXPRESSION) { f = new Factor_Expression(*((Factor_Expression*)*i)); factors.push_back(f); } if ((*i)->who_am_i() == Factor::FUNCTION) { f = new Function(*((Function*)*i)); factors.push_back(f); } if ((*i)->who_am_i() == Factor::VARIABLE) { f = new Variable(*((Variable*)*i)); factors.push_back(f); } } }
The goal of this constructor is to create new objects as you can see and put them into a vector array. I'm sure there's a simpler way to do this, something more OOP friendly, but I can't think of it.