mardi 14 décembre 2021

Is it a good practice to have a use a template in a derived class? C++ 11

I am currently new to C++ in the working world (learnt C++ academically). This is my first job where C++ is the base requirement.

May I ask -

  1. When do I use a template for a class?
  2. Is there any ideal or good practices that uses a template in a derived class, where the base class does not inherit any templates?

For example:

class Base {};

<typename T>
class Derived : public Base {};

The reason why I need to inherit from a base is because I need to store objects where it can be referenced from the base, and thereafter have a common factory method where I can pull information out.

Aucun commentaire:

Enregistrer un commentaire