C ++,g ++编译错误函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C ++,g ++编译错误函数相关的知识,希望对你有一定的参考价值。
我不能做这个工作,它没有得到编译,我不知道哪里是错误。你能帮助我吗?
我正在创建一个程序,对“n”int数字的向量进行排序。
这是代码:
#include <iostream>
#include <vector>
using namespace std;
void selection_sort(vector <int>& v){
int last=v.size() -1;
for(int i=0; i<last; ++i){
int k = min(v, i, last);
//Vector, position "i", and last vector position send to function
swap(v[k],v[i]);//swap positions
}
}
int min(const vector <int>& v, int left, int right){
这是终端的错误:
g++ -o sortinglearn.x sortinglearn.cc
sortinglearn.cc: In function ‘void selection_sort(std::vector<int>&)’:
sortinglearn.cc:14:27: error: no matching function for call to
‘min(std::vector<int>&, int&, int&)’
int k = min(v, i, last);
^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
from /usr/include/c++/7/ios:40,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from sortinglearn.cc:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate:
template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
min(const _Tp& __a, const _Tp& __b)
^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: template argument
deduction/substitution failed:
sortinglearn.cc:14:27: note: deduced conflicting types for parameter
‘const _Tp’ (‘std::vector<int>’ and ‘int’)
int k = min(v, i, last);
答案
@Quentin Ty队友!我以某种方式修复了它,在min
之前声明了selection_sort
函数。
以上是关于C ++,g ++编译错误函数的主要内容,如果未能解决你的问题,请参考以下文章