I'm currently working on a web application in which I have an Element class for objects on the page, and Tag classes for the HTML tags that make up those page objects:
Each instance of the Element class should contain an ordered, variable sized set of Tag objects. The references I've read have generally only referred to polymorphism in the context of pointers:Code:#include <string> using std::string; class Tag { // represents all tags // ... public: const virtual string write()=0; // should return the HTML to represent the tag } class EmptyTag : protected Tag { // for tags like <img/>, <br/>, etc. //... public: const string write(); } class EnclosingTag : protected Tag { // for tags like <p>text here</p> //... public: const string write(); }
but have not said whether and how it can be used in other contexts. Would it be possible to just use a vector?Code:class Base; class Derived : public Base; class OtherDerived : public Base; Base* polymorphicPointer;
or would I have to use some more complicated solution?Code:std::vector<Tag> myTags;
If so, what would people suggest?
Thanks.