GDB跳过我的代码! [英] GDB skips over my code!

查看:126
本文介绍了GDB跳过我的代码!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我定义了一个类

  DataLoggingSystemStateReceiver 
{
DataLoggingSystemStateReceiver b $ b://初始化列表
{
// stuff
}

// ...这里的其他函数

} ;

在main中,我实例化DataLoggingSystemStateReceiver如下:

  int main()
{
// ... run stuff
传感器传感器

DataLoggingSystemStateReceiver dlss();

Log :: notice(started);
return 0;但是,当我在gdb中遍历这个代码时,它运行:
<$>

p>

 传感器传感器(端口,定时器); 

跳过

  DataLoggingSystemStateReceiver dlss(); 

并继续

  Log :: notice(started); 

是什么?






EDIT:更改

  DataLoggingSystemStateReceiver dlss 

  DataLoggingSystemStateReceiver dlss; main()中的

,该行执行。

解决方案

这是:

  DataLoggingSystemStateReceiver dlss(); 

不声明自动变量。它声明了一个名为 dlss 的函数,它不带任何参数并返回 DataLoggingSystemStateReceiver



您需要:

  DataLoggingSystemStateReceiver dlss; 

对象将被默认初始化,因此对于类类型,将调用默认构造函数。 / p>

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.

这篇关于GDB跳过我的代码!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆