求助:STL的问题
#include "Test.h"
void Test::PrintTest(){
cout << "Print Test!\n";
return;
}
bool iteratorA::less_than( int v1, int v2){
return v1 < v2 ? true : false;
}
bool iteratorA::greater_than(int v1, int v2){
return v2 > v1 ? true : false;
}
vector<int> iteratorA::filter( const vector<int> &vec,
int filter_value,
bool (*pred)(int,int)){
vector<int> nvec;
for(int ix = 0; ix < vec.size(); ++ix){
if( pred(vec[ix], filter_value) ){
nvec.push_back(vec[ix]);
}
}
return nvec;
}
template <typename ArrayType>
void displayArrayA(const ArrayType &array){
for(int i = 0; i < array.size(); ++i){
cout << "array[" << i << "]: " << array[i] << endl;
}
return;
}
int main(){
cout << "Hello World!\n";
/*
Test* test = new Test;
try{
test->PrintTest();
}catch(const std::exception &error){
cerr << error.what() << endl;
delete test;
}
delete test;
*/
auto_ptr<Test> test(new Test);
test->PrintTest();
//vector<int> big_vec;
int iarray[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
vector<int> big_vec(iarray,iarray + 15);
int value = 10;
iteratorA iteratora;
vector<int> lt_10 = iteratora.filter(big_vec, value, iteratorA::less_than);
displayArrayA(lt_10);
return (0);
}
我是一个新手,关于上面的代码,我在VC6中能够编译成功,但是,在Eclipse + MinGW却发生了下面的错误。请大侠们
指点,谢谢先。。。!!!
**** Incremental build of configuration Debug for project Hello C++ ****
make -k all
'Building file: ../hello.cpp'
g++ -O0 -g3 -Wall -c -fmessage-length=0 -ohello.o ../hello.cpp
../hello.cpp: In member function `std::vector<int, std::allocator<int> > iteratorA::filter(const std::vector<int, std::allocator<int> >&, int, bool (*)(int, int))':
../hello.cpp:22: warning: comparison between signed and unsigned integer expressions
../hello.cpp: In function `void displayArrayA(const ArrayType&) [with ArrayType = std::vector<int, std::allocator<int> >]':
../hello.cpp:60: instantiated from here
../hello.cpp:32: warning: comparison between signed and unsigned integer expressions
'Finished building: ../hello.cpp'
' '
'Building target: Hello.exe'
g++ -o Hello.exe hello.o
'Finished building: Hello.exe'
Build complete for project Hello C++
说是这条语句有问题:displayArrayA(lt_10);
谢谢大侠帮帮忙吧。呜呜呜。。。