E
E. Robert Tisdale
Default said:Creating objects via new is of course very important in using
polymorphism and design patterns such as Abstract Factory.
Something else that should *always* be avoided.
Default said:Creating objects via new is of course very important in using
polymorphism and design patterns such as Abstract Factory.
seesaw said:Is it right thing to always avoid using "new" to create objects?
What if, after starting the application,
then decide which and how many objects to create?
(Seems like, under such situation,
there is no other choice but using "new")
#include <iostream>cat main.cc
0 = a[0]g++ -Wall -o main main.cc
./main 10
seesaw said:Is it right thing to always avoid using "new" to create objects?
What if after starting the application, then decide which and how
many objects to create? (Seems like under such situation is there
no other choice but using "new")
E. Robert Tisdale said:Something else that should *always* be avoided.
E. Robert Tisdale said:Something else that should *always* be avoided.
Michiel said:Now that is a statement which is even less backed by facts.
An Abstract Factory makes perfect sense,
if the design requires creation of objects
whose type is not statically known.
And wouldn't _that_ have been a mistake! The standard containers are a great
facility to have, but I doubt you honestly think that they're sufficient for all
needs and that mechanisms to create alternatives would have been removed from the
language even had containers been present from day one. Even the addition of
reasonable smart pointers wouldn't obviate the need for manual dynamic allocation
in certain contexts.
Andrew Koenig said:Not really; I'd use std::allocator instead, because it gives me
finer-grained control over construction and destruction than new does.
new expressions are a bit odd - the array version calls the default
constructor, which is hardly helpful in general. You also have to
match your array and non-array versions. Seems like we could do
without it if we had another, more fundamental container type, like
"std::buffer" (with no capacity, just size). std::buffer could be used
to build std::vector!
seesaw said:Is it right thing to always avoid using "new" to create objects? What if
after starting the application, then decide which and how many objects to
create? (Seems like under such situation is there no other choice but using
"new")
Andrew said:What does std::allocator not do that you want?
What does std::allocator not do that you want?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.