Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
December 11, 2006 Struct vs Class | ||||
---|---|---|---|---|
| ||||
Have I got the difference between Class and Struct right? Have I missed anything? Functionality Class Struct -------------------------------------------------- Default instantiation :: Heap Stack Constructor :: this() void opCall() Destructor :: ~this() None Argument passing :: by Reference by Value Assignment :: Reference Value bit copy bit copy Inheritance :: Single None Interfaces :: Multiple None Order of data members :: Defined by Defined by in RAM compiler coder ------------------------------------------------- -- Derek (skype: derek.j.parnell) Melbourne, Australia "Down with mediocrity!" 11/12/2006 3:04:33 PM |
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | "Derek Parnell" <derek@nomail.afraid.org> wrote in message news:1jh0lfbbfm2rr.1nza8l988sfh1.dlg@40tude.net... > Constructor :: this() void opCall() Isn't it usually "static StructName opCall()"? Unless you use another convention. |
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> Have I got the difference between Class and Struct right? Have I missed
> anything?
>
> Functionality Class Struct
> --------------------------------------------------
> Default instantiation :: Heap Stack
> Constructor :: this() void opCall()
> Destructor :: ~this() None
> Argument passing :: by Reference by Value
> Assignment :: Reference Value
> bit copy bit copy
> Inheritance :: Single None
> Interfaces :: Multiple None
> Order of data members :: Defined by Defined by
> in RAM compiler coder
> -------------------------------------------------
>
>
Also you should include the new features for overloading opAssign and the implicit call of static opCall. (I think there's some difference there for structs and classes, though I haven't looked at it too closely yet).
--bb
|
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote: > Have I missed anything? > > Functionality Class Struct > -------------------------------------------------- ... Access to outer elements from nested constructs Yes No "outer" property for "this" Yes No > ------------------------------------------------- |
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> Have I got the difference between Class and Struct right? Have I missed
> anything?
>
> Functionality Class Struct
> --------------------------------------------------
> Default instantiation :: Heap Stack
> Constructor :: this() void opCall()
> Destructor :: ~this() None
> Argument passing :: by Reference by Value
> Assignment :: Reference Value
> bit copy bit copy
> Inheritance :: Single None
> Interfaces :: Multiple None
> Order of data members :: Defined by Defined by
> in RAM compiler coder
> -------------------------------------------------
Overridable (virtual) functions: yes/no. Unless that's self-understood under "inheritance".
Lockable (can be the target of "synchronized"): yes/no.
Andrei
|
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Derek Parnell wrote:
> Have I got the difference between Class and Struct right? Have I missed
> anything?
One big thing I'm missing... invariants! Really handy for catching bugs in struct like point/rectangle etc...
---
Paolo Invernizzi
|
December 11, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | Well, these are kinda the superficial differences.
The main one being classes are used for OOP, so, they support polymorphism (runtime binding of function calls), and objects have an identity. i.e. two objects are different objects, even if they have the same state at this moment in time.
Where as structs are meant to be simple aggregates of data. Instances of a struct have no identity.
Derek Parnell wrote:
> Have I got the difference between Class and Struct right? Have I missed
> anything?
>
> Functionality Class Struct
> --------------------------------------------------
> Default instantiation :: Heap Stack
> Constructor :: this() void opCall()
> Destructor :: ~this() None
> Argument passing :: by Reference by Value
> Assignment :: Reference Value
> bit copy bit copy
> Inheritance :: Single None
> Interfaces :: Multiple None
> Order of data members :: Defined by Defined by
> in RAM compiler coder
> -------------------------------------------------
>
>
|
December 13, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Karen Lanrap | Karen Lanrap wrote:
> Derek Parnell wrote:
>
>> Have I missed anything?
>>
>> Functionality Class Struct
>> --------------------------------------------------
> ...
> Access to outer elements
> from nested constructs Yes No
> "outer" property
> for "this" Yes No
>> -------------------------------------------------
These are really just one difference: the concept of outer objects.
Stewart.
|
December 13, 2006 Re: Struct vs Class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote:
> These are really just one difference: the concept of outer objects.
Correct. "including" combines them.
|
Copyright © 1999-2021 by the D Language Foundation