Reputation: 379
I am trying to use a boost::function in my ReceiveRequest to run on its own thread but I must be sending the wrong parameters. (At least thats what I think the compiler is trying to tell me)
Here are the lines that is causing the issue:
//some variables for the function call
std::string something("");
asio::system_error e();
asio::thread daThread();
CurrentRequest.payload;
//attempts to call function
CurrentRequest.Callback(something, &e, CurrentRequest.payload); //line 184
CurrentRequest.Callback(something, &e, &CurrentRequest.payload); //line 185
Here is what the compiler is telling me:
g++ -o ss -pthread -lrt StringSocket.cpp main.cpp -I ~/asio/include -I ~/boost/include ~/boost/lib/*.a
StringSocket.cpp: In member function ‘void StringSocket::ProcessReceive()’:
StringSocket.cpp:184: error: no match for call to ‘(ReceiveRequest::receiveCallback) (std::string&, asio::system_error (*)(), void*&)’
/home/jsander/boost/include/boost/function/function_template.hpp:761: note: candidates are: R boost::function3<R, T1, T2, T3>::operator()(T0, T1, T2) const [with R = void, T0 = std::string*, T1 = asio::system_error&, T2 = void*]
StringSocket.cpp:185: error: no match for call to ‘(ReceiveRequest::receiveCallback) (std::string&, asio::system_error (*)(), void**)’
/home/jsander/boost/include/boost/function/function_template.hpp:761: note: candidates are: R boost::function3<R, T1, T2, T3>::operator()(T0, T1, T2) const [with R = void, T0 = std::string*, T1 = asio::system_error&, T2 = void*]
Here is the ReceiveRequest class:
class ReceiveRequest
{
typedef boost::function<void (std::string *message, asio::system_error& e, void *payload) > receiveCallback;
public:
receiveCallback Callback;
void* payload;
ReceiveRequest(receiveCallback _Callback, void* _payload)
{
Callback = _Callback;
payload = _payload;
}
~ReceiveRequest() { }
};
These errors seem to be making a distinction between pointers and references to variables. I thought they could be used interchangeable as parameters. boost::function also appears to turn all of my local variables into references.
I am also confused that one of my parameters passes as "e" turns into "asio::system_error (*)()". Why is there a second pair of parenthesis added to my variable?
Upvotes: 1
Views: 108
Reputation: 26080
There are multiple issues here:
asio::system_error e();
This isn't doing what you want. Because of the way C++ syntax works, this is actually declaring a function e
that takes no parameters and returns an asio::system_error
. If you add a void
in the parenthesis, this becomes easier to see. It should be declared as:
asio::system_error e;
Secondly, your typedef
says your function should take a reference to a system_error
: asio::system_error& e
. However, when you pass the above in (assuming you fix the first problem), you're trying to pass a pointer:
CurrentRequest.Callback(..., &e, ....); // Should just be 'e'
Upvotes: 4