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


is there way avoid code replication across different constructors of 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])     {     } } 

it's called delegating constructor. in case this:

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

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -