C ++代码无法编译并产生奇怪的错误

Cap*_*emo 2 c++ c++11 c++14

这段c ++代码无法编译。有人知道为什么吗?

#include <functional>
#include <algorithm>
#include <vector>
#include <iostream>

int main(int a, char** v) {

        std::vector<uint32_t> v1 {1,2,3,4};
        std::vector<uint32_t> v2 {0};
        std::vector<uint32_t> v3 {5,4,3,11};
        std::vector<uint32_t> v4 {10,11,2};


        auto vector_is_subset = [] (const std::vector<uint32_t> a, const std::vector<uint32_t> b) -> bool {

                std::sort(a.begin(), a.end());
                std::sort(b.begin(), b.end());
                return std::includes(a.begin(), a.end(), b.begin(), b.end());
        };


        std::vector<uint32_t> f {};

        if (v1.empty() || v2.empty() || v3.empty() || v4.empty() ){
                std::cout << "a vector is empty" << std::endl;
        }


        return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到以下输出

g ++ a.cpp -std = c ++ 14

在/ usr / include / c ++ / 7 / algorithm:62:0中包含的文件中,来自a.cpp:2:

/usr/include/c++/7/bits/stl_algo.h:实例化'void std :: __ insertion_sort(_RandomAccessIterator,_RandomAccessIterator,_Compare)[with _RandomAccessIterator = __gnu_cxx :: __ normal_iterator>; _Compare = __gnu_cxx :: __ ops :: __ Iter_less_iter]:/ usr / include / c ++ / 7 / bits / stl_algo.h:1885:25:从'void std :: ____ final_insertion_sort(_RandomAccessIterator,_RandomAccessIterator,_ = and [=) __gnu_cxx :: __ normal_iterator>; _Compare = __gnu_cxx :: __ ops :: __ Iter_less_iter]'/usr/include/c++/7/bits/stl_algo.h:1971:31:从'void std :: __ sort(_RandomAccessIterator,_RandomAccessIterator,_Compare)必填[与_RandomAccessIterator :: __ normal_iterator>; _Compare = __gnu_cxx :: __ ops :: __ Iter_less_iter]'/usr/include/c++/7/bits/stl_algo.h:4836:18:从'void std ::

Sla*_*ica 8

std::sort修改容器以使其排序,但是您将lambda的参数声明为const

auto vector_is_subset = [] (const std::vector<uint32_t> a, const std::vector<uint32_t> b) -> bool
                         // ^^^^                           ^^^^^
Run Code Online (Sandbox Code Playgroud)

删除它们,它应该可以编译。