bind2nd

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;
}
 
V

Victor Bazarov

PS said:
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?
[...]
l.remove_if(bind2nd(greater<int>(), i));
[...]

I don't think there is something wrong with the program. It more
likely something is wrong with the Sun's library implementation.
Seems that the implementation has 'list::remove_if' a non-template,
but a plain function that expects a pointer to a function.

Upgrade your Sun compiler or use a better Standard Library.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,231
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top