template ref parameter

Regan Heath regan at netmail.co.nz
Wed Nov 21 04:32:24 PST 2012


On Wed, 21 Nov 2012 12:30:08 -0000, Regan Heath <regan at netmail.co.nz>  
wrote:

> On Wed, 21 Nov 2012 12:02:45 -0000, Jack Applegame  
> <japplegame at gmail.com> wrote:
>
>> void foo(ref int a) { a--; }
>> struct functor(A...) {
>>   void function(A) functor;
>> }
>> functor!int f;    // functor!(ref int) - wrong
>> f.functor = &foo; // Error: cannot implicitly convert expression (&  
>> foo) of type void function(ref int a) to void function(int)
>
> Hmm.. well I got past your initial problem, but I have a new one..
>
> alias void function(ref int) funcType;
>
> void foo(ref int a) { a--; }
>
> struct functor(A...) {
>    A func;
> }
> void main()
> {
>    functor!funcType f;
>    f.func = &foo; //Error: f.func is not an lvalue
> }

Just realised what is happening here. "f.func = " is trying to call the  
function, and assign &foo to the "void" result.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d-learn mailing list