My class has an array of pointers (Code edited for illustrating point)
class IMX6S::IMX6SAnalogIn : public AP_HAL::AnalogIn {
public:
IMX6SAnalogIn();
private:
IMX6S::IMX6SAnalogSource* _channels[2];
};
class IMX6S::IMX6SAnalogSource : public AP_HAL::AnalogSource {
public:
friend class IMX6S::IMX6SAnalogIn;
IMX6SAnalogSource(int16_t pin, float initial_value);
};
I want to initialize the _channels array in the initializer list of the constructor so I attempt the following
IMX6SAnalogIn::IMX6SAnalogIn() :
_channels{&IMX6SAnalogSource(0,0.0f),&IMX6SAnalogSource(1,0.0f) }
{
}
However I get a warning - Taking address of temporary. in the initializer list
Is this way of initializing the array in the initializer list incorrect?
Note - I cannot dynamically allocate memory. Everything has to be statically allocated.