我使用Windows 10,Visual Studio 2017 v15.7.1和auto [a, b] = func1(x, y, z); // auto func1() -> std::tuple<double, double, double>
[a, b] = func2(x, y, z); // same signature as func2
这个带结构化绑定的简单代码不会编译:
E1277 attributes are not allowed here
说double a, b;
[a, b] = func1(x, y, z);
[a, b] = func2(x, y, z);
。
下面的代码不会编译,同样的错误
auto [a, b] = func1(x, y, z);
auto [a, b] = func2(x, y, z);
代码
auto [a1, b1] = func1(x, y, z);
auto [a2, b2] = func2(x, y, z);
也不会编译,理所当然地抱怨重新定义。
它编译的唯一方法是
{{1}}坦率地说,这很难看。
这个功能是这样设计的吗?还是VC ++ bug?
答案 0 :(得分:8)
结构化绑定必须具有/home/xus/torch/install/bin/luajit: /home/xus/torch/install/share/lua/5.1/trepl/init.lua:389: module 'usr/local/hdf5' not found:No LuaRocks module found for usr/local/hdf5
no field package.preload['usr/local/hdf5']
no file '/home/supermicro/.luarocks/share/lua/5.1/usr/local/hdf5.lua'
...
no file '/usr/local/lib/lua/5.1/usr/local/hdf5.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
/home/xus/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
prepro_img.lua:10: in main chunk
[C]: in function 'dofile'
.../xus/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00405d50
。来自cppreference:
省略auto
...
attr(optional) cv-auto ref-operator(optional) [ identifier-list ] = expression ;
- 可能是cv限定的类型说明符cv-auto
...
变体;只需更改auto
部分
我们可以看到= expression
是强制性的。
如果您想重新绑定cv-auto
和a
,请使用std::tie
:
b