469,140 Members | 1,164 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

bind2nd

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;
}
Dec 3 '05 #1
1 2856
PS wrote:
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
Dec 3 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by red floyd | last post: by
3 posts views Thread by ES Kim | last post: by
2 posts views Thread by flyaflya | last post: by
4 posts views Thread by dzikus | last post: by
8 posts views Thread by Noah Roberts | last post: by
2 posts views Thread by benben | last post: by
2 posts views Thread by benben | last post: by
3 posts views Thread by Bruintje Beer | last post: by
4 posts views Thread by responsible | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.