digitalmars.D.learn - Struct vs Class
- Derek Parnell <derek nomail.afraid.org> Dec 10 2006
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Dec 10 2006
- Bill Baxter <dnewsgroup billbaxter.com> Dec 10 2006
- Karen Lanrap <karen digitaldaemon.com> Dec 10 2006
- Stewart Gordon <smjg_1998 yahoo.com> Dec 12 2006
- Karen Lanrap <karen digitaldaemon.com> Dec 12 2006
- "Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail erdani.org> Dec 10 2006
- Paolo Invernizzi <arathorn NOSPAM_fastwebnet.it> Dec 11 2006
- Hasan Aljudy <hasan.aljudy gmail.com> Dec 11 2006
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: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.
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









"Jarrett Billingsley" <kb3ctd2 yahoo.com> 