I am looking to create a default constructor for my object in C++, which, when called, simply calls another constructor but with fixed values.
I have been looking at similar problems: Are default constructors called automatically for member variables? and Explicitly defaulted constructors and initialisation of member variables Which indicate, that when a default constructor is called, the default constructors of the member variables, unless specified, are also called.
However, the issue I have is that the member variables (from the ARMmbed library) I am using, do not have default constructors - hence this is not working.
Is there a way to "delay" this issue, because, in the constructor called by the default constructor, all these member variables are allocated to and it all works out - is there a way of letting the compiler know this?
Thanks very much!
The header and implementation code I am using is below!
class Motor: public PwmOut
{
public:
//Constructor of 2 pins, and initial enable value
Motor(); //Default constructor
Motor(PinName dutyPin, PinName enable_pin, bool enable);
private:
bool enable; //Boolean value of enable
DigitalOut enablePin; //Digital out of enable value
};
Implementation:
/**
* Default constructor
**/
Motor::Motor() //I don't want to initialise member variables here
{
this = Motor::Motor(p23,p24,true); //As they are initialised in this constructor anyway?
}
/**
* Constructor for Motor class. Takes 1 PwmOut pin for PwmOut base class and 1 pin for DigitalOut enable
**/
Motor::Motor(PinName dutyPin, PinName enable_pin, bool enable):
PwmOut(dutyPin), enablePin(enable_pin)
{
//Logic in here - don't really want to duplicate to default constructor
}