dimanche 17 mai 2020

Constructor delegation vs default argurments

I am wondering which of the following classes implements the preferred method:

class foo
{
public:
    foo(int a, int b, int c);
    foo(int a, int b) : foo(a, b, 0){};
    ~foo();
    //...
};

class bar
{
public:
    bar(int a, int b, int c = 0);
    ~bar();
    //...
};

From my point of view, they basically do the same. I would personally prefer the bottom one, because less code (to maintain). But is my preference the best practice?

Aucun commentaire:

Enregistrer un commentaire