我试图从this了解J.F. Sebastian算法,但我尝试编译它
(gcc/g++ 4.8
)得到一个奇怪的编译器错误:
const int n=101,m=31,k=*16-1;
int i;
srand(time(NULL));
for(i=0;i<n;i++) x[i]=rand();
std::sort(x,x+m,std::greater<float>());
std::sort(x+m,x+n,std::greater<float>());
float v=nsmallest_iter(x,x+m,x+m+1,x+n,n-1-k,std::greater<float>());
添加我得到的-std=c++11
标志:
from blabla.cpp:2:
blabla.cpp: In instantiation of ‘typename std::iterator_traits<_Iterator>::value_type nsmallest_iter(RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, RandomAccessIterator, size_t, Compare) [with RandomAccessIterator = float*; Compare = std::greater<float>; typename std::iterator_traits<_Iterator>::value_type = float; size_t = long unsigned int]’:
blabla.cpp:58:64: required from here
blabla.cpp:28:66: error: ‘issorted’ was not declared in this scope
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
blabla.cpp:28:35: error: ‘issorted’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
blabla.cpp:28:66: note: ‘issorted’ declared here, later in the translation unit
assert(issorted(firsta,lasta,less) && issorted(firstb,lastb,less));
^
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
您正在使用C ++ 11功能,因此您必须使用编译标志
-std=c++11
或
-std=c++0x
对于第二个问题,您可能遗漏了一些标题或者代码存在问题。
编辑:issorted可能会引用std::is_sorted
。它可以在包含#include <algorithm>
答案 1 :(得分:0)
将issorted
替换为std::is_sorted
(如果不存在,请添加#include <algorithm>
)
(用C ++ 11编译)