Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 14, 2014 Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
I thought this was possible, but DMD 2.065 doesn't allow it, saying "no constructor for int": int* p = new int(3); Is something like this planned for the future? I know we can already do: int n = int(3); |
June 14, 2014 Re: Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 06/13/2014 10:29 PM, Meta wrote:
> I thought this was possible, but DMD 2.065 doesn't allow it, saying "no
> constructor for int":
>
> int* p = new int(3);
>
> Is something like this planned for the future? I know we can already do:
>
> int n = int(3);
Those both compile with 2.066
Ali
|
June 14, 2014 Re: Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Saturday, 14 June 2014 at 06:39:56 UTC, Ali Çehreli wrote:
> On 06/13/2014 10:29 PM, Meta wrote:
>> I thought this was possible, but DMD 2.065 doesn't allow it, saying "no
>> constructor for int":
>>
>> int* p = new int(3);
>>
>> Is something like this planned for the future? I know we can already do:
>>
>> int n = int(3);
>
> Those both compile with 2.066
>
> Ali
Right, thanks. It's difficult to keep track of what's already released and what's in Git HEAD.
|
June 14, 2014 Re: Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | Would auto i = (int*)(3); make sense? Does it work? |
June 14, 2014 Re: Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | On Saturday, 14 June 2014 at 08:09:12 UTC, Philippe Sigaud via Digitalmars-d-learn wrote:
> Would
>
> auto i = (int*)(3);
>
> make sense?
>
> Does it work?
No:
Error: C style cast illegal, use cast(int*)3
And I don't think it should, because the heap allocation that you're probably expecting should be explicit IMO. For me it's also unintuitive, because I would read it as constructing a pointer that points to the address 3.
|
June 14, 2014 Re: Universal Construction Syntax for Pointers? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | > And I don't think it should, because the heap allocation that you're probably expecting should be explicit IMO. For me it's also unintuitive, because I would read it as constructing a pointer that points to the address 3.
I agree. I'm trying to get a feel on the limits of this new
'type(value)' syntax.
|
Copyright © 1999-2021 by the D Language Foundation