digitalmars.D - struct constructors
- "Matthew" <admin stlsoft.dot.dot.dot.dot.org> Mar 08 2005
- John Reimer <brk_6502 yahoo.com> Mar 08 2005
- "Andrew Fedoniouk" <news terrainformatica.com> Mar 08 2005
- John Reimer <brk_6502 yahoo.com> Mar 08 2005
- "Andrew Fedoniouk" <news terrainformatica.com> Mar 08 2005
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
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
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
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
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









John Reimer <brk_6502 yahoo.com> 