another compiler bug?
Aarti_pl
aarti at interia.pl
Thu Jan 10 01:41:25 PST 2008
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...
> Maybe you really wanted to take the allocate an object, and then get the
> address of the reference? I guess so, but I don't know if that's
> possible in a single statement.
No, it won't work in my program as I must return this pointer from function.
Thanks for your post!
BR
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d-learn
mailing list