A new class -->String
Dan
murpsoft at hotmail.com
Thu Apr 5 14:29:15 PDT 2007
Jari-Matti Mäkelä Wrote:
> Dan wrote:
> > I totally disagree with Class'ing a simple data type just to introduce
> > functions to handle it.
>
> I'm sure we all agree on that. Extending previously closed classes is a
> valuable feature in modern object oriented programming.
...
> a few special cases. You cannot do something like
>
> auto myS = "moo";
>
> char[] opMul(char[] str, int count) {
> char[] tmp;
> for(int i=0; i<count; i++) tmp ~= str;
> return tmp;
> }
>
> auto s2 = myS * 3; // = "moomoomoo"
If what you want is operator overrides, I'd recommend a struct. Semantically, it's equivalent to using the simple data type, while allowing you to sugar coat it in the same way as a class.
More information about the Digitalmars-d
mailing list