Hello
Im having trouble with bind2nd with a "user defined" class.
First I tried with integers using less<> and it works alright.
But when I would like it to work with my Person class, the complier (Borland Builder 5) is
giving me a hard time.
So this is my main.cpp:
struct MyLess
{
bool operator()(Person &first, int &n)
{
return (first.getAge() < n);
}
};
MyLess myLess;
int main()
{
vector<Person> v;
Person p;
for (int i = 0; i < 15; i++)
{
Person p("Sean", i);
v.push_back(p);
}
vector<Person>::iterator iter = v.begin();
//iter = partition(v.begin(), v.end(), bind2nd(myLess<p>(), 10));
//iter = partition(v.begin(), v.end(), bind2nd(MyLess<p>(), 10) );
//iter = partition(v.begin(), v.end(), bind2nd(myLess(), 10) );
//iter = partition(v.begin(), v.end(), bind2nd(MyLess(), 10) );
(Every object will of course be called "Sean", but they have different "age".)
Each and every one of these calls to partition() gives me error which I dont understand.
The first one:
[C++ Error] main.cpp(30): E2094 'operator<' not implemented in type 'MyLess' for arguments
of type 'Person'
Do I have to implement a "op<" in "MyLess"?
And my operator< which is defined as friend in Person.cpp:
bool operator<(Person &p1, Person &p2)
{
return (p1.getAge() < p2.getAge());
}
I guess there is something wrong with my functor.
Any Ideas?
/ Sean
Im having trouble with bind2nd with a "user defined" class.
First I tried with integers using less<> and it works alright.
But when I would like it to work with my Person class, the complier (Borland Builder 5) is
giving me a hard time.
So this is my main.cpp:
struct MyLess
{
bool operator()(Person &first, int &n)
{
return (first.getAge() < n);
}
};
MyLess myLess;
int main()
{
vector<Person> v;
Person p;
for (int i = 0; i < 15; i++)
{
Person p("Sean", i);
v.push_back(p);
}
vector<Person>::iterator iter = v.begin();
//iter = partition(v.begin(), v.end(), bind2nd(myLess<p>(), 10));
//iter = partition(v.begin(), v.end(), bind2nd(MyLess<p>(), 10) );
//iter = partition(v.begin(), v.end(), bind2nd(myLess(), 10) );
//iter = partition(v.begin(), v.end(), bind2nd(MyLess(), 10) );
(Every object will of course be called "Sean", but they have different "age".)
Each and every one of these calls to partition() gives me error which I dont understand.
The first one:
[C++ Error] main.cpp(30): E2094 'operator<' not implemented in type 'MyLess' for arguments
of type 'Person'
Do I have to implement a "op<" in "MyLess"?
And my operator< which is defined as friend in Person.cpp:
bool operator<(Person &p1, Person &p2)
{
return (p1.getAge() < p2.getAge());
}
I guess there is something wrong with my functor.
Any Ideas?
/ Sean