I have a class
class BarBase { };
and a derived template class that 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 Bar instances and store pointers in them in the vector of another Foo class
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 to find elements in myBars with fields object and action equal to the parameters of this function? As you can see, I cannot directly access fields like this->myBars[i]->action , since these fields are not (and cannot be) members of BarBase .
EDIT I can compare object . I add virtual size_t getObject (){}; in BarBase and redefine it in Bar as virtual size_t getObject (){ return (size_t)this->object; }; virtual size_t getObject (){ return (size_t)this->object; }; . Then I compare the two size_t , but I do not know how to convert action to number ...
source share