August 07, 2011 Something weird with threads. | ||||
---|---|---|---|---|
| ||||
While messing with threads from std.concurrency, I've been getting this weird problem. The code below, runs perfectly fine. ------------------------------------------- import std.concurrency; void main( ) { spawn( &func ); } void func( ) { } -------------------------------------------- But when func( ) is moved to a class: ------------------------------------------- import std.concurrency; void main( ) { auto c = new C; spawn( &c.func ); } class C { void func( ) { } } -------------------------------------------- doesn't compile at all. It produces the following errors: - Error: template std.concurrency.spawn(T...) does not match any function template declaration - Error: template std.concurrency.spawn(T...) cannot deduce template function from argument types !()(void delegate()) Am I doing it wrong? Is there a workaround? Thanks. |
August 07, 2011 Re: Something weird with threads. | ||||
---|---|---|---|---|
| ||||
Posted in reply to BizarreCake | > - Error: template std.concurrency.spawn(T...) cannot deduce
> template function from argument types !()(void delegate())
As the message already tells a class method yields a delegate and not a function.
Check if that method could be made static.
But if you really need to do it this way, you may create a static wrapper function that calls the method on a particular class instance. You should be able to use a function literal as well.
|
Copyright © 1999-2021 by the D Language Foundation