I think I have a basic problem of understanding instantiating objects from classes or rather storing them in variables / arrays.
I have a class
class sensor{
public:
// Constructor
sensor() {
isObject = true; // Define that an object has been instantiated
}
bool isObject = false; // By default set this property to false
};
and an array
sensor sensorList[5];
I thought that the defined array is only reserving as much memory as it is necessary for storing the maximum amount of possible elements (of type sensor, so here 5 x 1 Byte for the property isObject).
But if I Serial.println e.g. sensorList[1].isObject I get 1 as result, so the object has already been "instantiated" (= the constructor has obviously been called) without any explicit sensor sensor1;. Can someone please explain me why?
std::cout <<"sensor constructor\n";within sensor ctor you will see it called 5 timessensor sensorList[5]will default-construct (i.e. call the constructor that can accept no arguments) each of the five elements of the array.