相关疑难解决方法(0)

Lambda作为默认参数失败

我使用以下代码获得了最新版本的clang和gcc的错误:

int main() {
    auto lambda = [] (auto = [] {}) {};
    lambda();
}
Run Code Online (Sandbox Code Playgroud)

Clang给出错误:

prog.cc: In function 'int main()':
prog.cc:3:12: error: no match for call to '(main()::<lambda(auto:1)>) ()'
     lambda();
            ^
prog.cc:2:35: note: candidate: template<class auto:1> main()::<lambda(auto:1)>
     auto lambda = [] (auto = [] {}) {};
                                   ^
prog.cc:2:35: note:   template argument deduction/substitution failed:
prog.cc:3:12: note:   couldn't deduce template parameter 'auto:1'
     lambda();
            ^
Run Code Online (Sandbox Code Playgroud)

为什么这会失败?

c++ c++17

17
推荐指数
2
解决办法
1095
查看次数

标签 统计

c++ ×1

c++17 ×1