digitalmars.D - Re: Hiding class pointers -- operator new()
- C. Dunn (10/22) Aug 16 2007 But Walter, how did you handle operator new()? It needs to be agnostic ...
Walter Bright Wrote:James Dennett wrote:But Walter, how did you handle operator new()? It needs to be agnostic about class/struct. class C{int x;}; stuct S{int x;}; typedef C MyType; //typedef S* MyType; MyType inst = new MyType; If you use the second typedef, this will not compile! That is the problem. Why not provide an operator New() which expects a pointer type when used for structs? Just have the compiler translate it. I cannot see how to write such a generic operator New() myself. This one small change would be a great boon to C/C++ programmer thinking of adopting D.Walter Bright wrote:That isn't my experience. In my work on DMDscript in D, I changed some types between struct and class to try out some variations, and found it to be a lot easier than in C++. For one thing, I didn't have to find and edit all the -> and .'s.Value types are fundamentally different from reference types. D gives you the choice.C++ gives you *more* choice by allowing easier migration between the two without imposing performance or syntactic differences.
Aug 16 2007