Using std.stdio.File in a class

Spacen Jasset spacenjasset at mailrazer.com
Tue Apr 8 08:52:22 PDT 2014


On Tuesday, 8 April 2014 at 15:15:37 UTC, Rene Zwanenburg wrote:
> On Tuesday, 8 April 2014 at 15:08:17 UTC, Spacen Jasset wrote:
>> On Tuesday, 8 April 2014 at 14:53:56 UTC, Adam D. Ruppe wrote:
>>> On Tuesday, 8 April 2014 at 14:52:02 UTC, Spacen Jasset wrote:
>>>> Are you not supposed to new structs anymore?
>>>
>>> Only if they're pointers. new File returns a File*, not a 
>>> File.
>>>
>>> But you shouldn't new a File because then the file won't be 
>>> automatically closed when it goes out of scope (RAII indeed).
>>>
>>> Your code should work if you just take out the new keyword.
>>
>> Perhaps the new keyword doesn't do what it used to do? I'll 
>> have to check all this out.
>
> Maybe you're confused with C#? In C# you have to use new for 
> structs too. In D new allocates something on the GC heap.

I don't think I am confusing it with C hash. I think it's 
changed. I found this in some old code I wrote years ago:

scope Stream file = new File(filename);



More information about the Digitalmars-d-learn mailing list