jeudi 28 juillet 2016

Is there any way to avoid code replication across different constructors of a class?

Is there any way to avoid code replication across different constructors of a class?

class sample
{
    int a, b;
    char *c;
public:
    sample(int q) :
      a(0),
      b(0), 
      c(new char [10 * q])
    {
    }

    sample() :
      a(0),
      b(0),
      c(new char [10])
    {
    }
}

Aucun commentaire:

Enregistrer un commentaire