How can I store delegates in array?
Chopin
robert.bue at gmail.com
Fri Nov 30 07:57:44 PST 2012
I tried the following:
import std.stdio;
import std.regex;
bool lol(string name, string val)
{
if (name == "lal")
if (val[0..3] == "2124")
return true;
return false;
}
bool lal(string name, string val) { return false; }
alias bool delegate(string, string) DgType;
void main()
{
struct Filter
{
private DgType[] delFuncs; // array with functions :D
public void add(DgType filter_func) {
delFuncs ~= filter_func;
}
}
auto x = Filter();
x.add(&lol);
x.add(&lal);
writeln(x);
}
Didn't work... just a bunch of errors...
t.d(28): Error: function t.main.Filter.add (bool delegate(string,
string) filter_func) is not callable using argument types (bool
function(string name, string v
al))
t.d(28): Error: cannot implicitly convert expression (& lol) of
type bool function(string name, string val) to bool
delegate(string, string)
t.d(29): Error: function t.main.Filter.add (bool delegate(string,
string) filter_func) is not callable using argument types (bool
function(string name, string v
al))
t.d(29): Error: cannot implicitly convert expression (& lal) of
type bool function(string name, string val) to bool
delegate(string, string)
Thanks for help!
More information about the Digitalmars-d-learn
mailing list