Answer the question
In order to leave comments, you need to log in
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
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
And where is the class object on which the method is called ??? Should look something like this:
SCPIParser * p = new ...;
...
(p->*(cmd->callback))()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question