I have a problem in C++ and i can't find answer for it. I have some classes:
class Xyz{
//...
};
class MyClass1: public Xyz{
//...
};
class MyClass2: public Xyz{
//...
};
class MyClass3: public Xyz{
//...
};
As you can see MyClass1, MyClass2 and MyClass3 have the same base class. Now i want to define some objects:
MyClass1 *object1 = new MyClass1();
MyClass2 *object2 = new MyClass2();
MyClass3 *object3 = new MyClass3();
After that i want to create an dynamic array with pointers at those objects (as i know it's possible) and an integer which save the number of elements in that array. I named that array someName and in future it should store object1, object2 and object3.
Xyz **someName;
int numberOfElements = 0;
Problems start here. someName is empty so i want to add something to it. But i don't know how to make an new array with given number of places for pointers to copy old element to it. This don't work ofcourse:
Xyz **someNameTemp = new Xyz[numberOfElements+1];
Any idea how the resizing function should look? Thanks for help.
Xyz* array[] = {object1, object2, object3};. It cannot be resized. By the way, whoever is declaring the standard library as off-limits to you, is not a good teacher of this subject. Consider studying on your own. Cheers & hth.,