Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 compiler error when using decltype(var) followed by internal type of "var"

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'
like image 668
Triumphant Avatar asked Jan 15 '13 03:01

Triumphant


1 Answers

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.)

like image 149
Lightness Races in Orbit Avatar answered Nov 04 '22 14:11

Lightness Races in Orbit