Angenommen habe ich eine Methode, die nun auf dieseDynamisch, welche Methode auf einem Vorlagentyp basiert verwenden
template<typename t,typename u>
std::shared_ptr<bar> MyClass::getFunct(std::string SomeStr)
{
.....
std::map<std::string,std::shared_ptr<foo> > j;
....
std::shared_ptr<u> collection(new u());
for (auto val : j){
val.second->getMethodA() //Will return object of type t <----LINE A
}
}
vereinfacht ich es als
getFunct<FirstType>("SomeString")
getFunct<SecondType>("SomeString")
getFunct<ThirdType>("SomeString")
Jetzt val.second
in Linie A bin mit hat 3 Methoden drin
val.second->getMethodA() //returns a type of FirstType
val.second->getMethodB() //returns a type of SecondType
val.second->getMethodC() //returns a type of ThirdType
Momentan verwende ich val.second->getMethodA()
mit Vorlagentyp FirstType
ist es für mich trotzdem angeben getMethodB
zu verwenden, wenn und getMethodC
Vorlagentyp SecondType
ist zu verwenden, wenn Vorlagentyp ThirdType
Das klingt wie das XY-Problem. Was ist das Designproblem, das Sie versuchen zu lösen? Binding-Funktionen zu Objekt ist möglich über 'std :: bind()' – lorro
Lassen Sie mich das Problem beheben –