lundi 6 septembre 2021

Which is the signature of a virtual function for a tailed function which use decltype to deduce return type in c++

I have a class with some (not pure) virtual functions which I use as a base type for other classes:

struct abstract_object {
    ...
}

in some of my other classes I need this tailed method:

struct Int : public abstract_object {
 
    /*virtual*/auto sum(Int* v) -> decltype(*this + *v) { return *this + *v; }
}

in all honesty, I don't know if this is legal, but, can I write a virtual version for the method in the base class? Until now I failed to find the right signature. c++11 is all I can stretch to. Thanks for your help

Aucun commentaire:

Enregistrer un commentaire