[Issue 5931] keyword new won't allow default initialization of a struct where it has a non-zero argument constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 6 12:35:57 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5931
Christopher the Magnificent <ultimatemacfanatic at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|keyword new insists on |keyword new won't allow
|calling a struct's |default initialization of a
|(non-zero argument) |struct where it has a
|constructor--in other |non-zero argument
|words, it won't allow |constructor
|default initialization; |
|also postblit this(this) |
|constructor dosen't get |
|called from "new |
|<structname>(<struct_instan |
|ce>)" |
--- Comment #3 from Christopher the Magnificent <ultimatemacfanatic at gmail.com> 2011-05-06 12:32:02 PDT ---
(In reply to comment #2)
> Post-blit is only called when you override the whole structure, as in:
>
> ----------------------------------------
> import std.stdio;
>
> struct S {
> this(this) {
> writeln("postblit");
> }
> }
>
> void main() {
> S s;
> S t;
> s = t; // <-- call postblit on s.
> }
> ----------------------------------------
>
> Pointer-assignment will *not* call post-blit as you have not blitted
> (memcpy-ed) anything.
*Shouldn't* post-blit be invokable by calling <File(file)>? Wouldn't this be a
desirable behavior?
If not, how do I allocate a default-initialized File struct in the heap using
<new> (so that I can follow that by overwriting the whole structure and get
post-blitter to run)?
what I'm taking about is this (this is what I want to do):
////////////////////////////
import std.stdio;
struct Tokenizer
{
File* file = null;
void
initFile(File f)
{
this.file = new File; // I want to allocate a new File struct and set
it to File.init -- DOESN"T WORK!
*this.file = f; // copy bits and then automatically call
post-blit File.this(this)
}
}
////////////////////////////
At the line above marked "DOESN'T WORK", the compiler refuses to allocate a new
default-initialized File struct. This is a problem
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list