I'm using following code with C++11 and getting a error that I'm not allowed to use typeof
!
What is the problem and how to fix this ?
The error :
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 is 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) {}
};
What you are looking for is decltype()
:
#define HIBERLITE_NVP(Field) hiberlite::sql_nvp< decltype(Field) >(#Field,Field)
// ^^^^^^^^
C++ does not have an operator called typeof
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With