P
PS
Hi,
I wrote the following code to try using bind2nd.
It compiles and works fine with g++ but a Sun compiler tells me :
"test_bind2nd.cpp", line 21: Error: Cannot cast from
std::binder2nd<std::greater<int>> to bool(*)(const int&).
Could you tell me if there's something wrong with the code itself?
Thanks,
PS
_______________________________________________________
#include <iostream>
#include <iomanip>
#include <functional>
#include <list>
#include <iterator>
using namespace std;
class A {
public:
A(int size, int ival) :
l(size, ival)
{};
void FillList() {
l.push_back(4);
l.push_front(2);
return;
}
void CleanList(int i) {
l.remove_if(bind2nd(greater<int>(), i));
return;
}
void PrintList() {
cout << "List: ";
copy(l.begin(), l.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
private:
list<int> l;
};
int main(int argc, char *argv[]) {
A a(10, 7);
a.PrintList();
a.FillList();
a.PrintList();
a.CleanList(6);
a.PrintList();
return EXIT_SUCCESS;
}
I wrote the following code to try using bind2nd.
It compiles and works fine with g++ but a Sun compiler tells me :
"test_bind2nd.cpp", line 21: Error: Cannot cast from
std::binder2nd<std::greater<int>> to bool(*)(const int&).
Could you tell me if there's something wrong with the code itself?
Thanks,
PS
_______________________________________________________
#include <iostream>
#include <iomanip>
#include <functional>
#include <list>
#include <iterator>
using namespace std;
class A {
public:
A(int size, int ival) :
l(size, ival)
{};
void FillList() {
l.push_back(4);
l.push_front(2);
return;
}
void CleanList(int i) {
l.remove_if(bind2nd(greater<int>(), i));
return;
}
void PrintList() {
cout << "List: ";
copy(l.begin(), l.end(), ostream_iterator<int>(cout, " "));
cout << endl;
}
private:
list<int> l;
};
int main(int argc, char *argv[]) {
A a(10, 7);
a.PrintList();
a.FillList();
a.PrintList();
a.CleanList(6);
a.PrintList();
return EXIT_SUCCESS;
}