Instantiating Templates Structs with defaults parameter

d coder dlang.coder at gmail.com
Thu Jun 9 07:16:59 PDT 2011


Greetings

Kindly look at the code below. When I try to compile it with DMD 2-53, I get
an error:

foo.d(9): Error: struct template.Foo(int n = 1) is used as a type

It would be convenient if I am allowed to use Foo as a type without passing
parameters (with parameterized functions that is the default behavior). I
want to understand if not being able to instantiate Foo with default
parameters is a bug in DMD? Otherwise If it is not allowed in D2, I want to
know why such a limitation is there.

Regards
- Puneet

import std.stdio;

struct Foo(int n = 1) {
  public int value = n;
}

void main()
{
  Foo foo; // Does not compile
  // Foo!() foo; // This works
  writeln("Value is, ", foo.value);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110609/86d46378/attachment-0001.html>


More information about the Digitalmars-d mailing list