Thats the kinda stuff that spelling and grammar checkers do isn't it? The only thing I'm doing here differently is I'm storing the junk for possible later use, storing it in a more logical & appropriate place, because 'cmon how the heck did that -245.1987 get in there? Its obvious that that -245.1987 was intended for something else. What we have here, is possibly 2 different input streams, well that crossed their streams, and thats a very very bad thing, like in the movie ghost busters. The least we can do is store the junk so we can straighten everything out after the Stay Puffed Marshmellow Man quits buggering us.
struct Data
{
virtual Data *Clone() = 0; //Make a copy of...whatever the heck kind of variable this is
virtualunsignedchar Type() = 0; //Get the type in case you need it (for most cases you shouldn't)
//Add more virtual functions here that would be handled by the derived classes, eg:
//virtual void Print() = 0;
//Other class-specific functions should be handled by the derived classes, not by the base (eg Get and Set functions)
virtual ~Data();
};
class String: Data
{
string Str;
public:
String(){}
String(const String& from) : Str(from.Str) {}
String(const string& from) : Str(from) {}
Data *Clone(){ returnnew String(*this); } //Make a new String
unsignedchar Type(){ return 1; } //This is a string
string Get(){ return Str; }
void Set(const string& from){ Str = from; }
};
class Int: Data
{
int Num;
public:
Int() : Num(0) {}
Int(const Int& from) : Num(from.Num) {}
Int(constint& from) : Num(from) {}
Data *Clone(){ returnnew Int(*this); } //Make a new Integer
unsignedchar Type(){ return 2; } //This is an Integer
string Get(){ return Num; }
void Set(constint& from){ Num = from; }
};
//And other similar derived classes
1 2 3 4
vector<Data*> Elements;
Elements.push_back(new String("Hello"));
Elements.push_back(new Int(1337));
//do whatever you want now :)