为什么C ++不允许我使用typeof?

时间:2013-04-18 10:15:12

标签: c++ visual-c++ c++11

我在C ++ 11中使用以下代码并收到错误,我不允许使用typeof

问题是什么以及如何解决这个问题?

错误:

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

这是我的代码:

#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是这样的:

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) {}
 };

1 个答案:

答案 0 :(得分:27)

您要找的是decltype()

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

C ++没有名为typeof的运算符。

相关问题