When "function pointer" meets "template"... I can't get rid of this compiling er
First, just to let you know that I use g++ to compile the src containing following code segments. Now lets start the business.
This is a templated class method I got:
and this is the function pointed by the function pointer:
for(num = 0; num < 5; num++)
cout << "***thread " << tmpThread->GetId() << " looped " << num << " times" << endl;
I have "bathList" as a pointer to SynchList<Thread *>:
SynchList<Thread *> *bathList = new SyncList<Thread *>;
and this is how I implement it (@ line 494 of the src):
bathList->Apply((void) (SimpleThread)(Thread *));
but I get this error msg everytime I try to compile the code:
../threads/thread.cc:494: parse error before '*'
Any help would be greatly appreciated.
Thank you all,
> and this is how I implement it (@ line 494 of the src):
> bathList->Apply((void) (SimpleThread)(Thread *));
Why are you casting the invocation parameter? Shouldn't this be:
Since SimpleThread is a "void (*)(Thread*)" this should be sufficient for template instanciation. You are attempting to instanciate the SynchList::Apply template method with the expression "(void)(SimpleThread)(Thread *)" which, as far as I can tell, will call SimpleThread(Thread *) and that is not a valid invocation argument. Think of Apply as a #define macro and that might make things clearer.
Templates are complex. Let me know if I am completely off-base here.
thank you bm17,
bathList->Apply(SimpleThread) actually works !!
I did what I did to try to follow the signature and didn't even notice that the argument (Thread *) itself is illegal at all. I think template instantiationg takes care of that by induction, and since "SimpleThread" is already a void function, so no need to re-cast (void) again ?
Am I heading the right direction ?
|All times are GMT -5. The time now is 07:01 PM.|