comparator

B

bil050

Hi,
I want to write comparator class,which compares int.These int are ID
in some other class container and in order to compare them - I want to
use these id just to retrieve appropriate objects from container and
make comparison based on object data
How can I do it?
Thanks
 
S

SG

I want to write comparator class,which compares int.These int are ID
in some other class container and in order to compare them - I want to

Then, just do it. What's the problem?

struct compare_ids
{
bool operator()(int a, int b) const {
return ...;
}
};
use these id just to retrieve appropriate objects from container  and
make comparison  based on object data

Then, you have to store a pointer or reference to this container
object in the comparator object as data member so you know where to
look things up in the operator() function.

Cheers!
SG
 
B

bil050

Then, just do it. What's the problem?

  struct compare_ids
  {
    bool operator()(int a, int b) const {
      return ...;
    }
  };


Then, you have to store a pointer or reference to this container
object in the comparator object as data member so you know where to
look things up in the operator() function.

Cheers!
SG

Can you please give an example how I store the pointer?(In
constructor?)
I use this comparator for set.(i.e. set<int,compare_ids>)
Thank you!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top