错误提示:
E:\things\算法设计与分析\实验1+实验2\未命名1.cpp In function 'int main()':
55 5 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Warning] lambda expressions only available with -std=c++11 or -std=gnu++11
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Error] no matching function for call to 'sort(std::vector<Order>::iterator, std::vector<Order>::iterator, main()::<lambda(const Order&, const Order&)>)'
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Note] candidates are:
62 0 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\algorithm In file included from E:/applications/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/algorithm
3 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp from E:\things\算法设计与分析\实验1+实验2\未命名1.cpp
4676 5 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_algo.h [Note] template<class _RAIter> void std::sort(_RAIter, _RAIter)
4676 5 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_algo.h [Note] template argument deduction/substitution failed:
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Note] candidate expects 2 arguments, 3 provided
62 0 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\algorithm In file included from E:/applications/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/algorithm
3 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp from E:\things\算法设计与分析\实验1+实验2\未命名1.cpp
4705 5 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_algo.h [Note] template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
4705 5 E:\applications\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\stl_algo.h [Note] template argument deduction/substitution failed:
E:\things\算法设计与分析\实验1+实验2\未命名1.cpp In substitution of 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<Order*, std::vector<Order> >; _Compare = main()::<lambda(const Order&, const Order&)>]':
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp required from here
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Error] template argument for 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)' uses local type 'main()::<lambda(const Order&, const Order&)>'
55 6 E:\things\算法设计与分析\实验1+实验2\未命名1.cpp [Error] trying to instantiate 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
解决方法:这个编译错误是由于你的编译器没有启用 C++11(或更高版本)支持,而 Lambda 表达式是 C++11 中的一个新特性。为了解决这个问题,你需要在编译时启用 C++11 支持。
对于 Dev-C++,你可以按照以下步骤操作:
- 打开 Dev-C++。
- 点击 “工具” 菜单。
- 选择 “编译选项”。
- 在 “代码生成” 或 “编译器” 选项卡中,找到 “语言标准” 或类似的设置。
- 选择 “ISO C++11” 或类似的选项。