468,103 Members | 1,351 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

clearly identifying instance+method - key problem

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

Nov 30 '06 #1
0 997

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by 5HH575-UAZWKVVP-7H2H48V3 | last post: by
reply views Thread by Stefan Behnel | last post: by
1 post views Thread by Water Cooler v2 | last post: by
4 posts views Thread by MuZZy | last post: by
6 posts views Thread by miked | last post: by
2 posts views Thread by Danny | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.