struct vs. class, int vs. char.

grauzone none at example.net
Tue Apr 28 10:42:51 PDT 2009


Jarrett Billingsley wrote:
> On Tue, Apr 28, 2009 at 12:07 PM, MLT <none at anon.com> wrote:
> 
>> What I don't like is that it seems that structs and classes should almost be interchangeable - one might implement something as a class and later want it to be a struct, or vice versa. It almost is actually a local decision. I might want something to be a class in one place, and a struct in another.
> 
> I hear this all the time from C++ users.  But in practice, it
> virtually never comes up.  I have never, in my five years of using D,
> wanted to change a class to a struct or vice versa, or ever seen
> anyone else doing that (or complaining about its difficulty).  The
> only people who complain are those who don't use the language ;)


Often I'd wish to statically allocate an object in the current context, 
like you can do with a struct. scope partially gives me what I want. It 
would be nice if "scope" could be used in other places:

class Bla {
     int member;
}

class Foo {
    scope Bla b; //object constructed here
}

static assert(Foo.classinfo.init.size == 5*4);

Yeah, you'd need a solution for how to call the ctor. Maybe the (very 
annoying) way of how initialization of final/const members is handled 
would be useful here.



More information about the Digitalmars-d mailing list