You cannot create an array of objects, as in Foo foo [N] , without a default constructor. This is part of the language specification.
Or do:
test * objs [50]; for() objs[i] = new test(1).
You do not need malloc (). You can simply declare an array of pointers.
c++decl> explain int * objs [50] declare objs as array 50 of pointer to int
But you probably should have some kind of automatic destruction like RAII.
OR publicly:
class TempTest : public test { public: TempTest() : test(1) {} TempTest(int x) : test(x) {} TempTest(const test & theTest ) : test(theTest) {} TempTest(const TempTest & theTest ) : test(theTest) {} test & operator=( const test & theTest ) { return test::operator=(theTest); } test & operator=( const TempTest & theTest ) { return test::operator=(theTest); } virtual ~TempTest() {} };
and then:
TempTest array[50];
You can consider each TempTest object as a test object.
Note: operator = () and the copy constructor are not inherited, so if necessary, follow the appropriate steps.
source share