(please forget the boost::variant.. i have test it and i give up on it)
i'm update my class for accept the class's\structs and more.
see the entire class:
error messages:Code:#ifndef VARIANT_H_INCLUDED #define VARIANT_H_INCLUDED #include <cstdlib> #include <iostream> #include <string> #include <algorithm> using namespace std; class variant { private: bool blnvoid; string a; void *b; public: variant() { blnvoid=false; a=""; b=NULL; } variant (string value) { a=value; } variant (double value) { a=to_string(value); } variant (int value) { a=to_string(value); } variant (long value) { a=to_string(value); } variant (void *value) { blnvoid=true; b=value; } friend istream& operator >>(istream &is,variant &obj) { is>>obj.a; return is; } friend ostream& operator <<(ostream &os,const variant &obj) { if (blnvoid==true) //here cames the error and i don't know why :( { os << obj.b; } else { 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 = (long 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
- "In function 'std:stream& operator<<(std:stream&, const variant&)':";
- "error: invalid use of non-static data member 'variant::blnvoid'";
- "error: from this location".
i don't understand these errors
can anyone explain to me?