GDB skips over my code!
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.
精彩评论