lundi 7 septembre 2020

How to check if a class has specific function to avoid compile time issues?

I have two class A and B, with a common function doing some operation on both of them with just a minor difference.

I tried using std::is_same, but looks like it won't prevent compile-time issues.

class A {
public: 
    void aSpecificFunctionToA() {
    }
};

class B {
};


template<typename T>
void someFunction(T obj) {
    if(std::is_same<T, A>::value)
    {
        obj.aSpecificFunctionToA();
    }
}

How to tackle this situation?

Aucun commentaire:

Enregistrer un commentaire