On Monday, 7 May 2012 at 09:18:11 UTC, David Nadlinger wrote:
On Monday, 7 May 2012 at 07:28:18 UTC, Mehrdad wrote:
Is this something that actually modifies the 'new' operator,
or is it just a separate factory function that my code would
need to switch to using?
Doing it without a separate factory function (and maybe
disabling new along with it by protecting the constructor) is
not possible in D. However, I don't quite see what it would
gain you in the first place – besides potentially screwing up
the semantics users expect from new…
What is your objective? What are you trying to achieve? I keep
getting the impression of you using a object factory and a static
function to create your objects, which would give you more
optional behavior but not using new directly.
class X {
static X makeX() {
X x;
//make X or OOP descendant and return by whatever rules you
need
return x;
}
}
Too much control is worse than not enough control. When I was
testing out C++11 and getting my hands dirty, bugs were easily
introduced where if you had to control certain gritty details,
all details had to be controlled for it to work. If you don't
have to control it, go around it to a simpler although slightly
longer solution.