www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - struct constructors

reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Are these still not in the language?

Was the argument against them that if they have ctors people will want 
dtors? Or something else?

In any case, I'd be quite prepared to have ctors and no dtors. Or to 
only allow ctors if the members are fundamental, etc. etc.
Mar 08 2005
next sibling parent John Reimer <brk_6502 yahoo.com> writes:
Matthew wrote:
 Are these still not in the language?
 
 Was the argument against them that if they have ctors people will want 
 dtors? Or something else?
 
 In any case, I'd be quite prepared to have ctors and no dtors. Or to 
 only allow ctors if the members are fundamental, etc. etc.
 
 
I totally agree. I vote that struct ctors be added to D. We have them for modules, why not for struct? -JJR
Mar 08 2005
prev sibling parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
struct size
{
  int x, y;
  static size opCall( int x, int y ) { size p; p.x = x; p.y = y; return p; }
}

size zs = size(2,3);

A bit ugly but works.

I like the idea of strongly distinguishing structs from classes, though.

Andrew.


"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message 
news:d0lhns$pdc$1 digitaldaemon.com...
 Are these still not in the language?

 Was the argument against them that if they have ctors people will want 
 dtors? Or something else?

 In any case, I'd be quite prepared to have ctors and no dtors. Or to only 
 allow ctors if the members are fundamental, etc. etc.




 
Mar 08 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Andrew Fedoniouk wrote:
 struct size
 {
   int x, y;
   static size opCall( int x, int y ) { size p; p.x = x; p.y = y; return p; }
 }
 
 size zs = size(2,3);
 
 A bit ugly but works.
 
 I like the idea of strongly distinguishing structs from classes, though.
 
 Andrew.
 
 
This is the known stop-gap solution. I don't think this solution would get good marks for readability. Furthermore, distinguishing structs from classes shouldn't be an issue. They are similar already in so many other ways that adding ctors to structs shouldn't make a difference: both structs and classes can contain function/methods; both can make use of operator overloading, etc. Understanding the differences between structs and classes should amount to just understanding D. -JJR
Mar 08 2005
parent "Andrew Fedoniouk" <news terrainformatica.com> writes:
   static size opCall( int x, int y ) { size p; p.x = x; p.y = y; return 
 p; }
 This is the known stop-gap solution. I don't think this solution would get 
 good marks for readability.
I agree. Again: "A bit ugly but works". Andrew.
Mar 08 2005