0

I tried to compile this example from https://github.com/augcampos/asterisk-cpp/wiki/Examples but I get this error:

root@debian:~# g++ TesteCpp.cpp -o tt -lasteriskcpp
TesteCpp.cpp: In function ‘int main()’:
TesteCpp.cpp:13:39: error: invalid conversion from ‘void (*)(asteriskcpp::ManagerEvent*)’ to ‘asteriskcpp::onManagerEventCallback_t {aka void (*)(const asteriskcpp::ManagerEvent&)}’ [-fpermissive]
In file included from TesteCpp.cpp:4:0:
/usr/local/include/asteriskcpp/manager/ManagerConnection.h:49:14: error:   initializing argument 1 of ‘void asteriskcpp::ManagerConnection::addEventCallback(asteriskcpp::onManagerEventCallback_t)’ [-fpermissive]

How to fix it?

TesteCpp.cpp:

//TesteCpp.cpp
#include <iostream>
#include "asteriskcpp/utils/LogHandler.h"
#include "asteriskcpp/manager/ManagerConnection.h"

using namespace asteriskcpp;
void eventCallback(ManagerEvent* me) {
    std::cout << std::endl << "TEST:EVENT" << me->toLog() << std::endl;
} 

int main() {
    ManagerConnection mc;
    mc.addEventCallback(&eventCallback); // add event listener
    if (mc.connect("192.168.1.6")) {
        if (mc.login("admin", "zzz")) {
            mc.logoff();
        }
    }
    mc.disconnect();
    return (0);
 }
2
  • could you provide more code please? At least TesteCpp.cpp (around line 13)? Commented Nov 28, 2013 at 15:57
  • Did you read the error message? You're passing one type of function pointer where a different type is expected. Commented Nov 28, 2013 at 16:18

1 Answer 1

5

Based on a quick scan of the code

void eventCallback(ManagerEvent* me) {
    std::cout << std::endl << "TEST:EVENT" << me->toLog() << std::endl;
} 

should be

void eventCallback(const ManagerEvent& me) {
    std::cout << std::endl << "TEST:EVENT" << me.toLog() << std::endl;
} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.