码:
auto main() -> int
{
int b = 42;
auto lambasta = [&]()
{
using B_type = decltype( b );
return B_type{};
};
(void) lambasta;
}
Run Code Online (Sandbox Code Playgroud)
使用MinGW g ++ 6.3.0进行无诊断编译-std=c++14 -Wall -pedantic-errors.无法使用Visual C++ 2015 update 3进行编译,
foo.cpp(6): error C2065: 'b': undeclared identifier
可能的解决方法:
template<typename T>
struct wrapper
{
using wrapped_t = T;
};
auto main() -> int
{
int b = 42;
auto lambasta = [&, a = wrapper<decltype(b)>()]()
{
using B_type = typename decltype( a ) ::wrapped_t;
return B_type{};
};
(void) lambasta;
}
Run Code Online (Sandbox Code Playgroud)
适用于 GCC 6.3 和 MSVC 2015 up 3
| 归档时间: |
|
| 查看次数: |
145 次 |
| 最近记录: |