pure or not pure?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Apr 10 12:34:20 PDT 2008
"Georg Wrede" wrote
> Ehrm. On second thought, it actually IS possible to end up in a situation
> where a just newed object may suddenly change in your hands, and also be
> referenced from other parts of the program.
>
> (I'll leave constructing an example as an exercise.)
>
> Now, the simplest thing to guarantee that not happening would be to deny
> newing of objects that have constructors.
In fact, I think the solution to this is to make a constructor that is pure
:)
The problem with this is that the 'this' pointer is mutable when passed to
the constructor, so you have mutable data being passed to a pure function.
However, it is 'unique' data that has not been initialized anywhere, so this
might be an exception to the rule.
Having the constructor pure solves any problems because you can't pass the
'this' pointer out to some global function that might store it somewhere.
-Steve
More information about the Digitalmars-d
mailing list