Why does c ++ not allow me to use typeof?

I use the following code with C ++ 11 and I get an error that I am not allowed to use typeof !

What is the problem and how to fix it?

Mistake:

 Error 10 error C2923: 'typeof' is not a valid template type argument for parameter 'C' 

Here is my code:

 #define HIBERLITE_NVP(Field) hiberlite::sql_nvp< typeof(Field) >(#Field,Field) class Person{ friend class hiberlite::access; template<class Archive> void hibernate(Archive & ar) { ar & HIBERLITE_NVP(name); //ERROR ar & HIBERLITE_NVP(age); //ERROR ar & HIBERLITE_NVP(bio); //ERROR } public: string name; double age; vector<string> bio; }; 

sql_nvp looks like this:

 template<class C> class sql_nvp{ public: std::string name; C& value; std::string search_key; sql_nvp(std::string _name, C& _value, std::string search="") : name(_name), value(_value), search_key(search) {} }; 
+8
c ++ c ++ 11 visual-c ++
source share
1 answer

What you are looking for is decltype() :

 #define HIBERLITE_NVP(Field) hiberlite::sql_nvp< decltype(Field) >(#Field,Field) // ^^^^^^^^ 

C ++ does not have an operator named typeof .

+27
source share

All Articles