I've a class
class BarBase {
};
and a derived template class, which stores a pointer to a member function and a pointer to an object of the same class
template<typename TypeName> class Bar: public BarBase
{
void ( TypeName::*action ) ( void );
TypeName* object;
};
I create instances of Bar
and store pointers to them in the vector of another class Foo
class Foo {
private:
vector<BarBase*> myBars;
...
};
Now to the question. Foo has a template function
template <typename TypeName>
void Foo::foo( TypeName* object , void ( TypeName::*action ) ( void ) )
In this function how do I find in myBars
elements with fields object
and action
equal to parameters of this function? As you can see, I can not directly access the fields like this->myBars[i]->action
since these fields are not (and can not be) members of BarBase
.
EDIT
I do can compare object
. I add a virtual size_t getObject (){};
to BarBase
and override it in Bar
like virtual size_t getObject (){ return (size_t)this->object; };
. Then I compare two size_t
, but I do not know, how to convert action
to a number...