Hello all,
I have 2 functions, both are identical except that one function is a template function. When I send the functions as function_pointer arguments to some other function, Metrowerks compiler complains for the template function.
template <typename T>
static void
call_stub (void *argument)
{
...........
..............
}
static void
call_stub_ (void *argument)
{
...........
..............
}
void register_callback ( (void (*)())(&call_stub<T>) ) ---- Gives error
void register_callback ( (void (*)())(&call_stub_) ) ---- Works fine.
Error Description:
Illegal explicit conversion from 'void' to 'void (*)()'.
Am I missing something here ? Is it a problem with the Metrowerks compiler ?
I am using PowerPC EABI Linker. Version: Code Warrior PowerPC ISA, Release 8.5 Build 50425.
Thanks !!
I haven't used C++ in Codewarrior but a qualified guess is the classic problem with linking of template functions:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
Whether Codewarrior supports export keyword or not, I have no idea.
as the error is a compilation failure and not a link time failure, I doubt it is that issue.
I would recommend to show a complete example and not just snippets, there is just too much undefined otherwise.
The text "void register_callback ( (void (*)())(&call_stub<T>) )" is not legal in C++ code as
it is neither a declaration nor a statemen, seems to be some psedocode.
Either way only a concrete instance of the call_stub template function has an address (call_stub<int>), the address of call_stub<T> only makes sense if used inside of another template.
Daniel
Actually the project on which I am working is quite a big one. So I just wrote the minimum stuff. Please check the code below, maybe better than previous time.
Thanks !!
class MyThread
{
template <typename T>
static void
call_stub (void *argument)
{
}
static void
call_stub_ (void *argument)
{
}
public:
template <typename T>
MyThread (T &function, bool joinable = false)
{
int result = register_callback ((void (*)())(&call_stub<T>), joinable, (void*)&function);
int result = register_callback ((void (*)())(&call_stub_), joinable, (void*)&function);
}
};
int
register_callback(
void (*entryAddr)(void),
bool joinable,
void *arg
)
{
// creates a thread and register the callback function.
}