clearly identifying instance+method - key problem

T

t.lehmann

I know about the problem about the standard:
"you can not cast a method to another type!"

There's a command class wrapping an instance and it's method; the
command is a shared pointer to a base class of concrete template
classes being able to adapt methods 0 - 3 parameters. The template
functions 'make_command' are creating the right implementations -
hidden to you.... - automatically deleted when leaving scope....

goal:
I want to be able to recognize wether two command objects are wrapping
the same instance+method:

Now the example:
// - - - - - - - - - - - - - - - - -
class X
{
public:
void test1() {}
void test2() {}
};

X inst1;
command cmd1 = make_command(&inst1, &X::test1);
command cmd2 = make_command(&inst1, &X::test2);
command cmd3 = make_command(&inst1, &X::test2); // intended!!

// MY PROBLEM:
assert(cmd2->key() == cmd3->key()); // ????
assert(cmd2->key() != cmd1->key()); // ????
// - - - - - - - - - - - - - - - - -

I've defined a virtual method at base class:
"virtual const void* key() const = 0;"

How do I've to implement the key method to get a unique key for a
(instance, method) pair
being unique (any pointer - as declared - or an int value):

// - - - - - - - - - - - - - - - - -
template <class TInstance, class TMethod>
class method_data : public command_base
{
public:
method_data(TInstance instance, TMethod method)
.....

virtual const void* key() const
{
return ???;
}
};
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top