Hiding class pointers -- was it a good idea?

Tristam MacDonald swiftcoder at gmail.com
Wed Aug 15 11:41:43 PDT 2007


Russell Lewis Wrote:
> But the worst of it all, IMHO, is what you (and others) have pointed 
> out: the lack of clarity about whether a declaration is a 
> struct-by-value or class-by-reference.  That means that if a container 
> was originally implemented as a struct, you can't ever change it to a 
> class, since that would require rewriting all of the code that uses it. 
>   Doesn't that violate one of the basic principles of Object Orientation 
> - the hiding of implementation?

I would tend to disagree. Classes are reference types, structs are value types. When I refactor something from a class to a struct, I *expect* the behavior of function arguments to switch from by-refrence to by-value.

Furthermore, since classes *cannot* be passed by value, it makes no sense to have additional syntax, which will lead to begginers writing 'Object o;' instead of 'Object* o;' - which will not compile under your suggestion.



More information about the Digitalmars-d mailing list