digitalmars.D.learn - Struct vs Class
- Derek Parnell (21/21) Dec 10 2006 Have I got the difference between Class and Struct right? Have I missed
- Jarrett Billingsley (4/5) Dec 10 2006 Isn't it usually "static StructName opCall()"? Unless you use another
- Bill Baxter (6/24) Dec 10 2006 Also you should include the new features for overloading opAssign and
- Karen Lanrap (6/11) Dec 10 2006 ...
- Stewart Gordon (3/15) Dec 12 2006 These are really just one difference: the concept of outer objects.
- Karen Lanrap (2/3) Dec 12 2006 Correct. "including" combines them.
- Andrei Alexandrescu (See Website For Email) (5/21) Dec 10 2006 Overridable (virtual) functions: yes/no. Unless that's self-understood
- Paolo Invernizzi (5/7) Dec 11 2006 One big thing I'm missing... invariants! Really handy for catching bugs
- Hasan Aljudy (8/26) Dec 11 2006 Well, these are kinda the superficial differences.
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
Dec 10 2006
"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.
Dec 10 2006
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
Dec 10 2006
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-------------------------------------------------
Dec 10 2006
Karen Lanrap wrote:Derek Parnell wrote:These are really just one difference: the concept of outer objects. Stewart.Have I missed anything? Functionality Class Struct --------------------------------------------------... Access to outer elements from nested constructs Yes No "outer" property for "this" Yes No-------------------------------------------------
Dec 12 2006
Stewart Gordon wrote:These are really just one difference: the concept of outer objects.Correct. "including" combines them.
Dec 12 2006
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
Dec 10 2006
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
Dec 11 2006
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 -------------------------------------------------
Dec 11 2006