找回密码
 立即注册
收起左侧

在 cpp 中返回该变量的地址 和 和直接在.h文件中返回变量...

0
回复
487
查看
[复制链接]
累计签到:1 天
连续签到:1 天
来源: 2024-5-16 16:31:51 显示全部楼层 |阅读模式
1Qter豆
请教 在 cpp 中返回该变量的地址 和 和直接在.h文件中返回变量地址不一样

在一个类display_sensor_info_Form中定义了个私有变量bool 类型
bool is_testing;

在构造函数中打印变量的地址
qDebug() << "is_testing :" <<  QString::number((int)&is_testing,16);



在mainwindow中调用
    p_display_sensor_info_Form = new display_sensor_info_Form(p_parameter,this);
    int dsif_addr = p_display_sensor_info_Form->return_addr();    qDebug() << QString::number(dsif_addr,16);
    dsif_addr = p_display_sensor_info_Form->return_addr_fb();        qDebug() << QString::number(dsif_addr,16);



在 cpp 中返回该变量的地址 和 和直接在.h文件中返回变量地址不一样
int display_sensor_info_Form::return_addr_fb()
{
    return (int)&is_testing;
}

和直接在.h文件中返回变量地址不一样
public:
    explicit display_sensor_info_Form(
            struct parameter_struct *p,
            QWidget *parent = 0);
    ~display_sensor_info_Form();
    void set_object_enable(bool state);
    int return_addr_fb();

    int return_addr()
    {
        return (int)&is_testing;
    }

运行结果
第一个为构造函数
第二个为.h中直接返回
第3个是在cpp文件中单独一个返回函数



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了