www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why is !() need with default template arguments

reply Jacob Carlborg <doob me.com> writes:
If I have a class like this:

class Class (T = int) {}

Then why can't I use it like this:

auto c = new C;

I have to do this:

auto c = new C!();
May 19 2009
parent reply Jeremie Pelletier <jeremiep gmail.com> writes:
Jacob Carlborg Wrote:

 If I have a class like this:
 
 class Class (T = int) {}
 
 Then why can't I use it like this:
 
 auto c = new C;
 
 I have to do this:
 
 auto c = new C!();

I think it is so the parser knows how to make the difference between the template symbol and an instance symbol.
May 19 2009
next sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
Jeremie Pelletier wrote:
 Jacob Carlborg Wrote:
 
 If I have a class like this:

 class Class (T = int) {}

 Then why can't I use it like this:

 auto c = new C;

 I have to do this:

 auto c = new C!();

I think it is so the parser knows how to make the difference between the template symbol and an instance symbol.

Can you do anything with a template except instantiate it? -Lars
May 20 2009
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Lars T. Kyllingstad wrote:
 Can you do anything with a template except instantiate it?
 
 -Lars

Pass it to another template as an alias argument. -- Daniel
May 20 2009
prev sibling parent reply "Tim Matthews" <tim.matthews7 gmail.com> writes:
On Wed, 20 May 2009 15:01:44 +1200, Jeremie Pelletier <jeremiep gmail.com>  
wrote:


 I think it is so the parser knows how to make the difference between the  
 template symbol and an instance symbol.

Can you explain a bit more on this? function templates dont require this by the way and I didn't think a template could ever be 'newed'
May 20 2009
parent Jeremie Pelletier <jeremiep gmail.com> writes:
Tim Matthews Wrote:

 On Wed, 20 May 2009 15:01:44 +1200, Jeremie Pelletier <jeremiep gmail.com>  
 wrote:
 
 
 I think it is so the parser knows how to make the difference between the  
 template symbol and an instance symbol.

Can you explain a bit more on this? function templates dont require this by the way and I didn't think a template could ever be 'newed'

Oh yeah you are right, it has already been filed as a bug.
May 20 2009