www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Idea for "scope" keyword

reply "Craig Black" <cblack ara.com> writes:
I thought it was very cool that .175 can instantiate an object on the stack 
using the scope keyword.  Would it be possible to take this one step further 
and be able to use this approach on class fields so that they are not 
instantiated on the heap?  I know you can use structs for this, but I find 
the limitations of D structs annoying.

class A {};

class B
{
  scope A a = new A;
}

-Craig 
Nov 29 2006
parent Sean Kelly <sean f4.ca> writes:
Craig Black wrote:
 I thought it was very cool that .175 can instantiate an object on the stack 
 using the scope keyword.  Would it be possible to take this one step further 
 and be able to use this approach on class fields so that they are not 
 instantiated on the heap?  I know you can use structs for this, but I find 
 the limitations of D structs annoying.
 
 class A {};
 
 class B
 {
   scope A a = new A;
 }

I have a feeling this is where Walter is heading with the scope keyword, so it's probably just a matter of time. Sean
Nov 29 2006