Destructor semantics

foobar foo at bar.com
Wed Aug 11 07:03:41 PDT 2010


Steven Schveighoffer Wrote:

> On Tue, 10 Aug 2010 20:28:32 -0400, bearophile <bearophileHUGS at lycos.com>  
> wrote:
> 
> > Jonathan M Davis:
> >> If attempts to use any reference types in destructors were a  
> >> compile-time error
> >> with a clear error message, that could go a long way in stopping people  
> >> from
> >> trying to misuse destructors.
> >
> > This sounds like a positive idea, maybe fit for an enhancement request.
> 
> No, reference types are not necessarily heap allocated.  Guys, the  
> distinction is heap vs. manual, not reference vs. value.  Value types can  
> be on the heap, and references can refer to non-heap data.
> 
> Adding artificial restrictions that force casting are not going to help at  
> all.
> 
> -Steve

I disagree. The distinction should be owned vs. not-owned and NOT heap vs. manual. Hence values vs. references. 

Simply put:
case 1)
  struct S;
  class C { S s;} // a C instance *owns* a S instance

case 2)
  class B;
  class C { B b; } // a C instance does *not* own a B instance

I believe that anything more complicated would require Bartosz' ownership system.


More information about the Digitalmars-d mailing list