Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
October 09, 2017 How to make commented code to compile? | ||||
---|---|---|---|---|
| ||||
import std.stdio; void test(ushort market, void delegate(ushort market, char* pc) callback) { for (auto i = 0; i < 10; i++) { callback(cast(ushort) i, cast(char*) null); } } void main() { test(cast(ushort) 1, (m, c) => writeln(m)); //test(cast(ushort) 1, (m, c) => { writeln(m); }); test(cast(ushort) 1, (ushort m, char* c) => writeln(m)); //test(cast(ushort) 1, (ushort m, char* c) => { writeln(m); }); } |
October 09, 2017 Re: How to make commented code to compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhuo Nengwen | On Monday, 9 October 2017 at 14:34:48 UTC, Zhuo Nengwen wrote:
> //test(cast(ushort) 1, (m, c) => { writeln(m); });
That's a function that returns a function.
Perhaps you meant to just remove the => and be left with a multi-line function.
|
October 09, 2017 Re: How to make commented code to compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 9 October 2017 at 14:54:33 UTC, Adam D. Ruppe wrote:
>> //test(cast(ushort) 1, (m, c) => { writeln(m); });
>
> That's a function that returns a function.
>
> Perhaps you meant to just remove the => and be left with a multi-line function.
I simplified the test codes. I want write mode codes in closure, such as:
test(cast(ushort) 1, (m, c) => {
writeln(m);
writeln(m);
});
|
October 09, 2017 Re: How to make commented code to compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zhuo Nengwen | On Monday, 9 October 2017 at 15:15:48 UTC, Zhuo Nengwen wrote:
> test(cast(ushort) 1, (m, c) => {
> writeln(m);
> writeln(m);
> });
Just remove the =>
(m, c) {
// code here
}
|
October 10, 2017 Re: How to make commented code to compile? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Monday, 9 October 2017 at 15:22:54 UTC, Adam D. Ruppe wrote:
> On Monday, 9 October 2017 at 15:15:48 UTC, Zhuo Nengwen wrote:
>> test(cast(ushort) 1, (m, c) => {
>> writeln(m);
>> writeln(m);
>> });
>
> Just remove the =>
>
> (m, c) {
> // code here
> }
Common mistake from people who worked with LINQ in C#.
|
Copyright © 1999-2021 by the D Language Foundation