Max G.
Max G.

Reputation: 13

C++ pointer to function [raspberry pi]

I'm trying to change a code written in C++ and run it on Raspberry Pi. It is an opensource code called freelss (https://github.com/hairu/freelss) and it's a laser scanner software. I tried to change some parts. For example, I expanded the system with some i2c chips and some buttons. Now I have changed the main.cpp and the main.h to scan the buttons. 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. 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. I always get the "setTask starts" but it won't come back to the main programm. Can please someone help me with the code?

Greets, Max

Upvotes: 1

Views: 141

Answers (1)

AntK
AntK

Reputation: 44

In the code you have shown you have not created an instance of Scanner, just a pointer.

Are you missing a:

scanner_Max = new Scanner ();

Or have you just not shown this?

Upvotes: 1

Related Questions