another compiler bug?
Aarti_pl
aarti at interia.pl
Thu Jan 10 01:49:58 PST 2008
Robert DaSilva 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.
>>
>> BR
>> Marcin Kuszczak
>> (aarti_pl)
>
> Because new returns a pointer to what you ask for. The reason new
> returns A when you ask it for A instead of *A like it would with
> anything else (anything not a class), is because A is actually a pointer
> to an instance of class A.
>
> The true is this is probably the best behaver, maybe... This raise some
> important question, I think.
The problem here is that compiler does not return pointer to class
reference as it should. That's why the line of code doesn't compile
although it should.
I don't see why its not possible for compiler to behave correctly. Of
course internally compiler should behave differently for classes than
for other types. But this is just a consequence of decision that classes
should be threated as value types in D.
BR
Marcin Kuszczak
(aarti_pl)
More information about the Digitalmars-d-learn
mailing list