I have one ABC class whose constructor is taking 3 arguments e.g x1, x2 and l. One sample code is shown below. I am trying to make another constructor in the same class ABC that should take different arguments but, I am unable to do. It might be a very general question but I am unable to get satisfactory answers.
class ABC {
protected:
X1& _x1;
X2& _x2;
Logger& _logger;
ABC(X1& x1, X2& x2, Logger& l):_x1(x1), _x2(x2),_logger(l) {}
ABC(X1& x1, Logger& l):_x1(x1),_logger(l) {} //getting error uninitialized reference member ‘ABC::_x2’
~ABC(){this->clear();}
void clear(){}
};
error uninitialized reference member ‘ABC::_x2'
_x2. If the reference toX2is optional maybe you should use a pointer to the X2 object or set_x2to a static instance of X2.