>A pointer to a new object is returned. The pointer
is then deleted. I'd like to rid the allocation/deletion of the
pointer. How would i achieve this?
The easiest way is the following
void computeLikeCrazy()
{
/*
test_class *p_test = (test_class *)testFactory::instance(stream);
if ( p_test )
{
// do something
delete p_test;
}
*/
}
Another way is to modify the testFactory::instance() so returns an
object instead of a pointer to an object, but then you can't refer to
the objects polymorphically. But it doesn't look like this is the
intent of this factory, which brings me to the question of why even
have it. Usually factories are used so the calling code doesn't care
about the specific type that's created, and thus you can deal with the
objects polymorphically. Also, it seems weird to me that the
testFactory::instance() returns a pointer to testFactory, and the
objects created thus have to derive from the factory. Usually
factories return a pointer to the object created, which aren't derived
from the factory. However in this factory, the types which are created
are hard coded by calling register_class. Why is this any better than
just calling new on the object?