C++ equivalent implementation of C# interface — thumbnail

Sometimes when learning from one language to another one, you may have to adapt your habit to the paradigm of language and it’s evolution degree.

Interface for C# developer is one of the pillar of SOLID Implementation Principles. In the C++ development the equivalence is not trivial enough in my opinion.

Response: virtual C++ classes

Interface in C#

// ICompte.cs file
public interface ICompte
{
    double retirerArgent(double montant);
    double ajouterArgent(double montant);
    double Solde { get; }
}

C++ equivalent implementation

// ICompte.h file
class ICompte
{
public:
    virtual double retirerArgent(double montant) = 0;
    virtual double ajouterArgent(double montant) = 0;
    virtual double getSolde() = 0;
};