Re: Destructor for struct invoked many times

2019-01-15 Thread Antonio Corbi via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 10:49:17 UTC, rikki cattermole wrote: Because you passed it by value to writeln, which goes on to pass it to many other functions. Thanks Rikki! I was thinking about something like that. Antonio

Destructor for struct invoked many times

2019-01-15 Thread Antonio Corbi via Digitalmars-d-learn
Hi, In this simple example, the destructor for the struct is invoked four more times than expected: import std.stdio; struct Person { string name; int age; ~this() { writefln("%s is gone (0x%x)", name, ); } } int main(string[] args) { Person* p = new Person; writefln

Re: Destructor for struct invoked many times

2019-01-15 Thread rikki cattermole via Digitalmars-d-learn
Because you passed it by value to writeln, which goes on to pass it to many other functions.