Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] CPP - Async Client's Connect Method gives "pure virtual method called" error. Anyone knows the error?

Hi all,

I am developing an application for developers in order to increase the efficient work. To do so, I created new methods for the codes in heavily use. Whenever I try to put the async client as attribute and a connect method in a different method, I get the following-up error:

pure virtual method called
terminate called without an active exception
Aborted (core dumped)

To give insights and make the understanding clear, a few snippet from my code as follow:

void A::connect(mqtt:connect_options opts, SCallback cb) {
        try {
            this->aclient.connect(opts, nullptr, cb);
        } catch (const mqtt::exception&) {
            throw std::runtime_error("Couldn't connect");
        }
}


Above methos to connect and I have setup:

void A::setup() {
        mqtt::connect_options opts;
        opts.set_keep_alive_interval(20);
        opts.set_clean_session(true);
        SCallback cb(this->aclient, opts, topic_name);
        this->aclient.set_callback(cb);
        this->connect(opts, cb); // throws the error.
}

Afterwards, the developer will do the job and close the connection. To illustrate:

void A::newJob() {
     this->setup();
     // here comes the work
     this->close();
}

Has anyone experienced it?
Thanks in advance 


Back to the top