In C ++, I am trying to implement my own class anyusing C ++. However, before I could test it (so if my implementation is bad, feel free to fix me), I got an error: error C2228: left of '.val' must have class/struct/uniontwice from using the function value()twice, which seems strange when it works everywhere, The only thing I could think of this is what decltypeinfront of the function is causing an error, but it shouldn't:
any
error C2228: left of '.val' must have class/struct/union
value()
decltype
Edit: I updated the way the variable is changed for the constructor template<class T> any(T V){...}
template<class T> any(T V){...}
class any{ protected: template<class T> struct variable{ public: T val; variable(){} variable(T t) : val(t){} }; variable<int> v; public: any(){ v.val = 0; } template<class T> any(T V){ variable<T> nV(V); v = nV; } ~any(){ delete &v; } decltype(v.val) value(){ // Error still here return v.val; } template<class T> static any create(T V){ return any(V); } };
, , :
T = NewT;
++ T , . "" , . (Python,...) ++ . ( T s), ( , ), .
T
, . , , , , (: ). , , ++, . , , Boost.Any, , . (: , )