Z
Z
Zakhar Alekseenko2014-06-14 13:19:43
C++ / C#
Zakhar Alekseenko, 2014-06-14 13:19:43

Can't call pointer to member function c++

Hello.
Can't call class member function by pointer.
I have a class for working with the SCPI protocol. Below is a simplified version of it.
It declares the scpi_command_callback_t type as a pointer to a class member function.
The member function pointer is stored in the scpi_command_t structure. But when I try to call a function by pointer, I get an error: 'callback' was not declared in this scope.

#ifndef SCPIPARSER_H
#define SCPIPARSER_H

class SCPIParser : public QObject
{
    Q_OBJECT
public:
    explicit SCPIParser(QObject *parent = 0);
public:
    typedef scpi_result_t(SCPIParser::*scpi_command_callback_t)();

    struct scpi_command_t {
        const char * pattern;
        scpi_command_callback_t callback;
    };
    scpi_result_t SCPI_CoreCls();
};
#endif

Inside the class is the following code
const scpi_command_t * cmd = context.paramlist.cmd;
(cmd->*callback)() ; //ошибка: 'callback' was not declared in this scope

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Misha Krinkin, 2014-06-14
@Zaher220

And where is the class object on which the method is called ??? Should look something like this:

SCPIParser * p = new ...;
...
(p->*(cmd->callback))()

UPDATE: I forgot the brackets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question