视觉 为什么C++不允许我使用typeof?
visual Why C++ doesn't allow me to use typeof?
我在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) {}
};
您要找的是decltype()
:
#define HIBERLITE_NVP(Field) hiberlite::sql_nvp< decltype(Field) >(#Field,Field)
// ^^^^^^^^
c++没有typeof
操作符
相关文章:
- 为什么在我的函数类型后使用引用运算符 (&) 允许我修改它返回的值?
- std::带有自定义缓冲区的 iostream 不允许我写入
- Visual Studio 2017 不允许我创建 C++ 专用模板
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?
- 错误:从"int"到"int*"的转换无效[-允许].我在下面提供了我的代码,我
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 为什么Visual Studio(2017;15.7.5)不允许我更改c ++关键字颜色
- HTTP POST 请求不允许我定义上下文类型
- 如何创建一个接口,允许我访问C++中的按钮(和其他ui)函数,该函数是使用python中的MFC实现的
- Bazel 允许我包含来自全局安装库的标头
- 为什么Visual Studio允许我在模板函数中使用私有成员(C++)?
- 新版本的 SDL 不允许我使用SDL_image
- 为什么C++不允许我在类中使用字符串作为数据成员?
- 为什么此代码不允许我接收整个数组?
- 为什么 C 允许我调用未声明的函数?
- 如何允许我的程序成功读取数字包含的文件
- 为什么我允许我为std :: vector设置end()
- 如果不允许我分配 rvalues 来引用为什么以下代码片段有效,这在内部如何工作?
- C++概念是否允许我的类在声明/定义中指定它满足某些概念?
- 视觉 为什么C++不允许我使用typeof?