lundi 29 avril 2019

Can I prevent implicit conversions of a derived class to a base class? [duplicate]

This question already has an answer here:

If I have eg:

class Base {}; 
class Derived : public Base {};

And a function:

Derived create_derived();

I'd like this to be ill-formed:

Base base = create_derived();

How can I do this?

Aucun commentaire:

Enregistrer un commentaire