Struct constructors callable twice?

Guilherme Vieira n2.nitrogen at gmail.com
Wed Jan 12 03:34:17 PST 2011


I've found this behavior while toying with opCall() in a struct:

import std.stdio;
struct Struct
{
    this(int value) { writeln("Struct.this(", value, ")"); }
    ~this() { writeln("Struct.~this()"); }
}
void main()
{
    Struct s = Struct(1); // prints `Struct.this(1)`
    s(2);                 // prints `Struct.this(2)`

    s(3);                 // prints `Struct.this(3)`

}                         // prints `Struct.~this()`


Notice how the destructor is only called once. If there was an opCall
defined for Struct, its reconstruction would shadow it. It certainly looks
like a bug to me, but since I'm "sure of nothing" in D I decided to post it
here. Is it really a bug?

-- 
Atenciosamente / Sincerely,
Guilherme ("n2liquid") Vieira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110112/12f705ab/attachment.html>


More information about the Digitalmars-d-learn mailing list