D
DaKoadMunky
Such an object has it's lifetime managed by the programmer. What's your
I interpreted your statement to mean that one should *only* use new for the
purposes of managing an objects lifetime.
I suggest that another purpose for using new is to defer the decision as to
which type of object to create to run-time.
It is true that the object will have its lifetime managed by the programmer but
the responsibility for lifetime management might be a consequence rather than a
goal.
void DoSomething(const string& typeIndicator)
{
Base* base = SomeFactoryFunction(typeIndicator);
delete base;
}
In this case the lifetime of the object presumably created with new is
identical to that of a variable with automatic storage duration. The need to
explicitly manage the lifetime of the object seems to be a consequence that
resulted from the need to delay the decision as to which kind of object to
create until run-time.
My only point is that lifetime management in one case might be exactly what is
desired whereas in another case it might just be a "side-effect".
point?
I interpreted your statement to mean that one should *only* use new for the
purposes of managing an objects lifetime.
I suggest that another purpose for using new is to defer the decision as to
which type of object to create to run-time.
It is true that the object will have its lifetime managed by the programmer but
the responsibility for lifetime management might be a consequence rather than a
goal.
void DoSomething(const string& typeIndicator)
{
Base* base = SomeFactoryFunction(typeIndicator);
delete base;
}
In this case the lifetime of the object presumably created with new is
identical to that of a variable with automatic storage duration. The need to
explicitly manage the lifetime of the object seems to be a consequence that
resulted from the need to delay the decision as to which kind of object to
create until run-time.
My only point is that lifetime management in one case might be exactly what is
desired whereas in another case it might just be a "side-effect".