lundi 7 octobre 2019

Template deduction of Base method called by Derived object

I'm trying to deduct a template of a function based on the class of the object invoking the function. How can I do this?

#include <type_traits>
struct B;

template<typename T>
bool f(const T*) { return std::is_same<T, B>::value; }

struct A {
    bool g() { return f(this); }
};
struct B:A {};

int main() {
        B b_obj;
        return b_obj.g(); // returns false
}

Making g virtual doesn't help either. How can I make b_obj.g() return true?

Aucun commentaire:

Enregistrer un commentaire