My problem is a bit complicated. I have one class (e: Component) which have Ports objects. When a Component create a Port object, it pass one of its methods to the Port constructor.
Methods signatures :
typedef std::vector<std::string> (Component::*ComponentMethod)(std::vector<std::string>);
It works fine if I do :
// in class Component
std::vector<std::string> Component::test_method( std::vector<std::string> ) {
std::cout << "Hello !\n";
// Do stuff
}
// Port ctor : Port( ComponentMethod callback );
Port* p = new Port(&Component::test_method);
Well... now, my problem is that I make subclasses of class Component, and I don't know how to pass sublcasses methods to a Port.
// in class SubtypeComponent
std::vector<std::string> SubtypeComponent::test_method2( std::vector<std::string> ) {
std::cout << "Hello !\n";
// Do stuff
}
// Port ctor : Port( ComponentMethod callback );
Port* p = new Port(&SubtypeComponent::test_method2);
// ERROR :'(
It seems normal : I guess the compiler expects precisely Component (only) method.
--> I'm looking for a solution to "dynamically" assign methods in Ports (but I don't think this is possible)
--> Maybe another solution should be usage of templates ? (defining "template methods pointers" instead of "Component methods pointers"), but I'm not sure.
Any help would be appreciated :)