ada - Calling a function passed as an access type that takes no parameters -


consider family of functions take no arguments , return same type:

function puzzle1 return answer_type; function puzzle2 return answer_type; function puzzlen return answer_type; 

i'd able pass functions subprogram , have subprogram call function , use result. can pass function subprogram defining access type:

type answer_func_type access function return answer_type; 

however, there doesn't seem way call passed-in function result:

procedure print_result(label    : in string;                        func     : in not null answer_func_type;                        expected : in answer_type)    result : answer_type; begin    result := func;     -- expected type "answer_type", found type "answer_func_type"    result := func();   -- invalid syntax calling function no parameters    -- ... end print_result; 

is there way in ada without adding dummy parameter functions?

you trying use pointer function, not function itself. dereference pointer , should well:

procedure main     type answer_type new boolean;     function puzzle1 return answer_type    begin return true;    end puzzle1;     type answer_func_type access function return answer_type;     procedure print_result(label    : in string;                           func     : in not null answer_func_type;                           expected : in answer_type)       result : answer_type;    begin       result := func.all; -- have pointer, dereference it!    end print_result;  begin     print_result ("aaa",puzzle1'access, true);  end main; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -