Passing Function as an argument to another Function
Andrea Fontana
nospam at example.com
Mon Dec 4 10:36:10 UTC 2017
On Monday, 4 December 2017 at 08:27:10 UTC, rikki cattermole
wrote:
> On 04/12/2017 8:22 AM, Vino wrote:
>> Hi All,
>>
>> Request your help on the below code, I want to send the
>> name of the function ( First and Second) from main as an
>> argument to another function(Mid) and the function "Mid" has
>> to execute the function(First and Second).
>>
>> Program:
>> import std.stdio;
>>
>> void First (string Ftext) {
>> writeln("First :", Ftext);
>> }
>>
>> void Second (string Stext) {
>> writeln("Second :", Stext);
>> }
>>
>> void Mid( string Fun, string Mtext) {
>> Fun(Mtext);
>> }
>>
>> void main () {
>> string Ftext = "FTest1";
>> string Stext = "STest2";
>> Mid(First, Mtext);
>> Mid(Second, Stext);
>> }
>>
>> From,
>> Vino.B
Maybe:
import std.stdio;
void Mid(alias Fun)(string Mtext) {
Fun(Mtext);
}
void main () {
string Ftext = "FTest1";
string Stext = "STest2";
Mid!First(Ftext);
Mid!Second(Stext);
}
More information about the Digitalmars-d-learn
mailing list