clearly identifying instance+method - key problem

Discussion in 'C++' started by t.lehmann@rtsgroup.net, Nov 30, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?S3Jpc3RpYW4=?=
    Replies:
    1
    Views:
    294
    Karl Seguin
    Feb 7, 2005
  2. M P
    Replies:
    1
    Views:
    451
  3. Raj Singh
    Replies:
    2
    Views:
    185
    Rick DeNatale
    May 29, 2008
  4. Greg Hauptmann
    Replies:
    9
    Views:
    231
    Loren Segal
    Jun 16, 2008
  5. phal
    Replies:
    7
    Views:
    88
    Vance M. Allen
    Sep 15, 2005
Loading...

Share This Page