1

Possible Duplicate:
demote boost::function to a plain function pointer

So I use Flash C++ Compiler (aka flascc, alchemy) and havin code like:

boost::function<var (void*, var)> f = boost::bind(&as3_socket::socket_socketData, this, _1, _2);                   
socket->addEventListener(flash::events::ProgressEvent::SOCKET_DATA, Function::_new(f, NULL));

get next compiler error:

$ g++ $JN -static -emit-llvm  -c src/utils/http/as3_socket.cpp -I../boost/boost_libraries/install-dir/include
src/utils/http/as3_socket.cpp: In constructor ‘as3_socket::as3_socket()’:
src/utils/http/as3_socket.cpp:75: error: no matching function for call to ‘AS3::ui::Function::_new(boost::function<AS3::ui::var ()(void*, AS3::ui::var)>*, NULL)’
/cygdrive/c/Users/Avesta/Downloads/FlasCC_1.0.1134176_11-09-2012/sdk/usr/bin/../../usr/include/AS3++/builtin.h:179: note: candidates are: static AS3::ui::Function AS3::ui::Function::_new()
/cygdrive/c/Users/Avesta/Downloads/FlasCC_1.0.1134176_11-09-2012/sdk/usr/bin/../../usr/include/AS3++/builtin.h:180: note:                 static AS3::ui::Function AS3::ui::Function::_new(AS3::ui::var (*)(void*, AS3::ui::var), void*)

So the question is how to get from boost::function<var (void*, var)> more C style var (*)(void*, var)

Community
  • 1
  • 1
myWallJSON
  • 9,110
  • 22
  • 78
  • 149
  • please someone create flascc tag... – myWallJSON Dec 06 '12 at 03:18
  • 1
    http://stackoverflow.com/questions/282372/demote-boostfunction-to-a-plain-function-pointer is what you want? – Karthik T Dec 06 '12 at 03:19
  • The error comes from g++. Doesn't matter that you invoked it via flascc. Doesn't matter that you wanted to convert the output to flash. This is a straightforward C++ question. – Ben Voigt Dec 06 '12 at 04:18

2 Answers2

1

The short answer is "You can't".

A boost function object may contain just a function pointer, but it might be the result of calling boost::bind () on some other function type and binding some of the parameters. It might also contain a function object.

Just because you can call it like a pointer to function doesn't mean it is a pointer to function.

[ Just noticed - link to other question above explains this in great detail ]

Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
0

You are asking the wrong question.

boost::function is a way to expressed "do something iin the future", jut it is not a pointer to a C++ function. I this too strong to fit as a pointer to a function.

However your call back interface is a C++ function that takes a void pointer and something else. Usually you provide the callback with both the void pointer and the function pointer.

So what you do is create a function that casts the void pointer to an object, then passes that object the rest of the arguments it was called with.

Make sure the type you cast to void and back is identical.

You could even turn a pointer to boost::function into the void ptr.

Note that this leaves you with a problem of managing the lifetime of the good pointed to object. Sucks don't it?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524