jeudi 28 juin 2018

check return type from templated method

I am working on c++11 application:

There I have some templated methods:

template <class P, class T>
void copyMemberToDocument(const P &childClass
                          std::string (T::*getter) (void) const) {
   auto member = (childClass.*getter)();
   // ...
}

Child class has multiple inheritance so I can have something like:

class A {
public:
  int getA() {return 1;}

class B {
public:
  const char* getB() {return "hello";}

class C : public A, public B {};

So I can do something like:

C c;
copyMemberToDocument(c, &B::getB);
copyMemberToDocument(c, &B::getA);

Is is possible to know if return value in templated method will be "const char*" or "int" in order to do different things depending on that?

Thanks and regards

Aucun commentaire:

Enregistrer un commentaire