lundi 4 mai 2020

Implement a virtual function that have different return type

class Distribution
{
    public:
       virtual type GenerateRandomNumber() = 0;
};

Within the Distribution class, there is a function that the derived classes must override it. One of the derived classes returns double and another one returns unsigned int.

class Gamma : public Distribution
{
   public:
      double GenerateRandomNumber() override;
};


class Poisson : public Distribution
{
   public:
      unsigned int GenerateRandomNumber() override;
};

I try auto as the return type of the GenerateRandomNumber() in Base class but it is not possible to use auto and virtual simultaneously. What should the return type be in Base class?

Aucun commentaire:

Enregistrer un commentaire