heres my variant class:
// *** ADDED BY HEADER FIXUP ***
#include <cstdlib>
#include <iostream>
#include <string>
// *** END ***
#ifndef VARIANT_H_INCLUDED
#define VARIANT_H_INCLUDED
class variant
{
string a="";
public:
variant (string value="")
{
a=value;
}
variant (double value)
{
a=to_string(value);
}
friend istream& operator >>(istream &is,variant &obj)
{
is>>obj.a;
return is;
}
friend ostream& operator <<(ostream &os,const variant &obj)
{
os<<obj.a;
return os;
}
friend istream &getline(istream &in, variant &s1)
{
getline(in, s1.a);
return in;
}
variant & operator = (int const & b)
{
a=to_string(b);
return *this;
}
variant & operator = (string const & b)
{
a=b;
return *this;
}
variant & operator = (double const & b)
{
a=to_string(b);
return *this;
}
variant & operator = (float const & b)
{
a=to_string(b);
return *this;
}
bool operator == (string const & b)
{
return (a==b);
}
operator string() const
{
return a; // return string member
}
operator double() const
{
return atof(a.c_str()) ;
}
};
#endif // VARIANT_H_INCLUDED
how can i update my class for accept struct's\class's\enum's and others?
why i don't use the template? because i must define the type before use it and then i can't use another type.