Templates in classes => what is wrong?
Ali Çehreli
acehreli at yahoo.com
Tue Apr 17 11:25:20 PDT 2012
On 04/17/2012 11:13 AM, Xan wrote:
> The idea is behind this https://gist.github.com/2407923
> But I receive:
>
> $ gdmd-4.6 algorisme_code.d
> algorisme_code.d:22: Error: variable codi cannot be read at compile time
> algorisme_code.d:22: Error: argument to mixin must be a string, not
(codi)
mixin is about code generation. For that reason the string that is given
to it must be available at compile time. Upon analyzing the code, that
is the case in your example, but because mixin() appears inside the
constructor, it cannot use a string parameter.
That's why I had used a template parameter for the function string.
There may be a number of solutions but only you can decide on what to
do. One solution is to mixin the delegate outside of the constructor and
pass as an argument along with its string representation:
// Untested code
this(... Funcio funcio, string funcioText) {
...
}
In main:
enum funcioText = "...";
auto funcio = mixin(funcioText);
... new Algorisme(..., funcio, funcioText);
Ali
More information about the Digitalmars-d-learn
mailing list