So, I've defined a class like
DataLoggingSystemStateReceiver
{
DataLoggingSystemStateReceiver()
: // initializer list
{
// stuff
}
// ... other functions here
};
In main, I instantiate DataLoggingSystemStateReceiver like so:
int main()
{
// ... run stuff
Sensor sensor(port, timer);
DataLoggingSystemStateReceiver dlss();
Log::notice("started");
return 0;
}
However, when I step through this code in gdb, it runs:
Sensor sensor(port, timer);
skips
DataLoggingSystemStateReceiver dlss();
and continues with
Log::notice("started");
What gives?
EDIT: By changing
DataLoggingSystemStateReceiver dlss();
to
DataLoggingSystemStateReceiver dlss;
in main(), the line executes. Can someone explain why?
This:
DataLoggingSystemStateReceiver dlss();
does not declare an automatic variable. It declares a function named dlss that takes no arguments and returns a DataLoggingSystemStateReceiver.
You want:
DataLoggingSystemStateReceiver dlss;
The object will be default initialized, so for your class type, the default constructor will be called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With