I already asked a similar question earlier, but I realise now that it was not specific enough.
What I want to do is find out if two pointers to some member function of a class, combined with an actual object of that class, are equal in the sense that both will "call" (in the sense described below) the same function of the same object. Basically, in this code:
bool isEqual(F* object1, void(F::*_fct1)(),
F* object2, void(F::*_fct2)())
{
TSpecificFunctor<F> specFunc1(object1, fct1);
TSpecificFunctor<F> specFunc2(object2, fct2);
return /* Something */;
}
Is there /* Something */ that will return true iff specFunc1 and specFunc2 are pointing to the same member function of the same given object?
There, TSpecificFunctor is defined as follows:
class TFunctor
{
public:
virtual void call() = 0;
};
template <class TClass> class TSpecificFunctor : public TFunctor
{
public:
TSpecificFunctor(TClass* _pt2Object, void(TClass::*_fpt)())
{
pt2Object = _pt2Object;
fpt=_fpt;
}
virtual void call() override
{
(*pt2Object.*fpt)();
}
private:
void (TClass::*fpt)();
TClass* pt2Object;
};
In other words, the function should return true iff specFunc1.call() will yield the exact same result as specFunc2.call().
EDIT: For example, this might be an application of what I'm trying to achieve:
class TClassB {
public:
TClassB() {...}
void doSomething()
{
...
}
void doSomethingElse()
{
...
}
private:
/* Some object-specific stuff. */
};
TClassB test;
isEqual(&test, &TClassB::doSomething, &test, &TClassB::doSomething); // ==> true
isEqual(&test, &TClassB::doSomething, &test, &TClassB::doSomethingElse); // ==> false
Aucun commentaire:
Enregistrer un commentaire