简体   繁体   English

指向函数的C ++指针[raspberry pi]

[英]C++ pointer to function [raspberry pi]

I'm trying to change a code written in C++ and run it on Raspberry Pi. 我正在尝试更改用C ++编写的代码并在Raspberry Pi上运行它。 It is an opensource code called freelss ( https://github.com/hairu/freelss ) and it's a laser scanner software. 这是一个名为freelss( https://github.com/hairu/freelss )的开源代码,并且是激光扫描仪软件。 I tried to change some parts. 我试图更改某些部分。 For example, I expanded the system with some i2c chips and some buttons. 例如,我用一些i2c芯片和一些按钮扩展了系统。 Now I have changed the main.cpp and the main.h to scan the buttons. 现在,我更改了main.cppmain.h来扫描按钮。 Everything works fine but now I wanted to have a button that starts the scanning process if I push it. 一切正常,但是现在我想有一个按钮,如果我按它可以启动扫描过程。

    Scanner (*scanner_Max);     
    std::cout << "before the first function" << std::endl;
scanner_Max->setTask(Scanner::GENERATE_SCAN);                           
    std::cout << "after the first function" << std::endl;

Now, if I push the button, It says "before the first function" goes into the setTask function and stays there. 现在,如果我按下按钮,它会说“在第一个函数之前”进入setTask函数并停留在那里。 It never comes back. 它永远不会回来。 So I never get the message "after the first function". 因此,我从来没有收到“第一个功能之后”的消息。

void Scanner::setTask(Scanner::Task task)
{
    std::cout << "setTask starts" << std::endl;   
    m_task = task;  
}

This is the function in scanner.cpp . 这是scanner.cpp的功能。 I always get the "setTask starts" but it won't come back to the main programm. 我总是得到“ setTask starts”,但不会回到主程序。 Can please someone help me with the code? 可以请人帮我提供代码吗?

Greets, Max 问候,最大

In the code you have shown you have not created an instance of Scanner, just a pointer. 在显示的代码中,您还没有创建Scanner实例,而只是创建了一个指针。

Are you missing a: 您是否缺少:

scanner_Max = new Scanner ();

Or have you just not shown this? 还是您只是没有展示?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM