C ++ 11编译器错误,当使用decltype(var)后跟内部类型“var” [英] C++11 compiler error when using decltype(var) followed by internal type of "var"

查看:170
本文介绍了C ++ 11编译器错误,当使用decltype(var)后跟内部类型“var”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual C ++ 2010,这里是我的代码片段:

  std :: set< int& s; 
decltype(s):: value_type param = 0;

我收到以下错误讯息,任何人都可以帮助我?

 >错误C2039:'value_type':不是`全局命名空间''的成员
>错误C2146:语法错误:缺少';'标识符'param'之前


解决方案>

这是去年在Connect上提出的Visual Studio错误。这是问题757545(无法使用decltype



这个问题有一个与@ iammillind's实际上相同的解决方法,除了它使用无论什么原因,在C ++ 11发布之前不久从< functional> 中删除​​的std :: identity std :: common_type 与一个模板参数等效; std :: remove_reference 在某些情况下是相同的。)


I'm using Visual C++ 2010, and here's my code snippet:

std::set<int> s;
decltype(s)::value_type param = 0;

I got the following error message, anyone can help me?

> error C2039: 'value_type' : is not a member of '`global namespace''
> error C2146: syntax error : missing ';' before identifier 'param'

解决方案

This is a Visual Studio bug that was raised last year on Connect. It is issue 757545 ("Cannot use decltype before scope operator").

The issue has a workaround listed alongside it that is effectively the same as @iammillind's, except it uses std::identity that was removed from <functional> shortly prior to the publication of C++11, for whatever reason. (std::common_type with one template parameter is equivalent; std::remove_reference is the same in some cases.)

这篇关于C ++ 11编译器错误,当使用decltype(var)后跟内部类型“var”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆