another compiler bug?
Christopher Wright
dhasenan at gmail.com
Thu Jan 10 04:55:09 PST 2008
Aarti_pl wrote:
> torhu pisze:
>> Aarti_pl wrote:
>>> How to create pointer to class?
>>>
>>> Below doesn't compile:
>>> ----
>>> A* cp = new A*;
>>> ----
>>> Type of new A* is (A**) while it should be A*.
>>>
>>> Any comments? (Maybe I missed something...)
>>>
>>> PS. I know that it is possible to create pointer to class in two steps.
>>
>>
>> Do you actually want to heap allocate a pointer to an object reference?
>
> Yes. After writing my post I discovered that 2 stage creation will not
> work for returning result from function. So my 'PS.' in fact is not
> solution.
>
> > Try this:
>> A* cp = *(new A*);
>
> I needed something like above. Unfortunately your solution doesn't work
> (don't know why). I get access violation in my program when returning
> '*(new A*)'.
>
> I managed to overcome bug in DMD with below:
>
> void func(T)() {
> static TYPE res;
> res = new T;
> return &res;
> }
>
> although it will cause memory leaks for every type for which the
> function is instantiated. So I consider bug in DMD as quite serious...
Does that work? With more than one instance created? I would think you'd
only ever be able to access the most recent one.
More information about the Digitalmars-d-learn
mailing list