473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1217

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2...
0
by: Stefan Behnel | last post by:
Hi! I just stumbled over this: ..>>> class test(object): .... def t(): pass .... t.testval = 1 .... ..>>> test.t
1
by: Water Cooler v2 | last post by:
I'm a web newbie so be gentle. Should I make this static/shared and put it in Glabal.asax or should I make it an instance method? Since it does not have constant parameters, is it thread-safe to...
4
by: Materialised | last post by:
Hi All, I have a strange issue, and I am not sure if it is a error on my part, or a visual studio bug. I am using VS.Net 2003 Enterprise. I have 2 event handlers as follows: Public...
4
by: MuZZy | last post by:
Hi, I'm retouching some utility classes used everywhere across our app, and there are certain methods used everywhere and pretty frequently. I'm changing them from instance methods to static...
6
by: miked | last post by:
If an instance method does not alter the containing class or any arguments of a referenced type is it thread safe? public void GetSomething() { return new Something(this.Name); } public string...
4
by: Pieter | last post by:
Hi, Using VB.NET 2005: When you use a Me.MyFunction to a Shared Method, you het the error "'Me' is valid only within an instance method.". Which is normal. But: Which keyword can you use...
2
by: Danny | last post by:
howdy, I have created an instance method for an object using new.instancemethod. It works great. Now the questions are: 1) how do I dynamically inspect an object to determine if it has an...
0
by: Maric Michaud | last post by:
Le Friday 05 September 2008 17:29:39 mercado mercado, vous avez écrit : Note that "self" for somemethod is just a local variable of the calling function. You cannot retrieve those local...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.