C++11 编译器错误,后跟 decltype(var) 后跟内部类型的"var"
C++11 compiler error when using decltype(var) followed by internal type of "var"
我使用的是Visual c++ 2010,下面是我的代码片段:
std::set<int> s;
decltype(s)::value_type param = 0;
我得到了以下错误信息,有人可以帮助我吗?
> error C2039: 'value_type' : is not a member of '`global namespace''
> error C2146: syntax error : missing ';' before identifier 'param'
这是去年在Visual Studio Connect上提出的一个错误。问题757545("不能在作用域操作符之前使用decltype ")。
这个问题旁边列出了一个与@iammillind相同的解决方案,除了它使用了在c++ 11发布前不久从<functional>
中删除的std::identity
,无论出于什么原因。(std::common_type
与一个模板参数等效;std::remove_reference
在某些情况下是相同的)
我看到在g++ 4.7.2版本中,代码编译得很好。所以它可能是MSVS中的编译器错误。暂时你可以试试下面的方法:
#ifdef COMPILER_BUG_STILL_THERE
template<typename T> struct Get { typedef T type; };
#define DECLTYPE(VAR) Get<decltype(VAR)>::type
#else
#define DECLTYPE(VAR) decltype(VAR)
#endif
用作:
DECLTYPE(s)::value_type param = 0;
免责声明:当然,使用此技巧时,您可能必须在模板内使用typename
。为此,您可以再添加一个宏,例如#define TDECLTYPE(VAR) typename DECLTYPE(VAR)
相关文章:
- 将函数类成员映射到类本身内部
- Boost Spirit,获取迭代器内部语义动作
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 内联函数中具有内部链接的全局变量
- 在函数内部的声明中初始化数组,并在外部使用它
- 如何在不知道向量大小的情况下输入向量内部的向量?
- 卷曲bracers内部结构的声明
- 从函数角度看ID到文件路径的内部与外部映射
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 如何在pugixml中获取节点的内部XML
- 使用C链接在函数内部创建C++模板
- 指针没有更新它在void函数内部指向的值
- 方法内部但循环仍得到预期的不合格id错误C++
- C++:具有内部链接的正向声明常量
- SDL_PollEvent() 无法捕获类函数内部SDL_QUIT?
- libcurl 和 DNS ttl 中的内部连接管理
- 如何修改 lambda 内部字符串的向量
- 如果我将嵌套映射作为多重映射的值,如何将值插入内部映射?
- 来自 Android 应用程序内部的 boost 类型的 boost::wrapexcept<boost::system::system_error> 的未捕获异常
- C++11 编译器错误,后跟 decltype(var) 后跟内部类型的"var"