[Doubt] Variadic arguments as reference (Possible?)

Regan Heath regan at netmail.co.nz
Fri Jun 14 06:20:26 PDT 2013


On Fri, 14 Jun 2013 13:55:29 +0100, MattCoder <mattcoder at gmail.com> wrote:
> I want to know if there is a way to pass variadic arguments as  
> reference? DMD says no!

import std.stdio;
import std.conv;

void sum(double value, double*[] numbers ...){
	foreach(ref num; numbers)
		*num = *num + value;
}

void main(){
	double a = 1, b = 2, c = 3;
	sum(10, &a, &b, &c);
	
	writeln("a = "~to!string(a),
			"\nb = "~to!string(b),
			"\nc = "~to!string(c));
}

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


More information about the Digitalmars-d-learn mailing list