| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
March 09, 2005 struct constructors | ||||
|---|---|---|---|---|
| ||||
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. | ||||
March 09, 2005 Re: struct constructors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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
| |||
March 09, 2005 Re: struct constructors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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.
>
>
>
>
>
| |||
March 09, 2005 Re: struct constructors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | 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
| |||
March 09, 2005 Re: struct constructors | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John Reimer | >> 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. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply