I'm having troubles getting a 2D class array to get filled with other class objects.
Base class:
class Base {
protected:
int x, y;
int moves;
char name;
bool occupied;
public:
Base();
friend ostream& operator<<(ostream& os, const Base& test);
};
Derived class:
class Derived : public Base {
private:
const int x = 10;
const int y = 60;
Base **array;
public:
Derived();
void printBoard();
};
Constructor of Derived class:
Creates the 2d dynamic array
Derived::Derived() {
array = new Base*[x];
for (int i = 0; i < x; i++)
array[i] = new Base[y];
}
Derived class 2:
class Derived2: public Base{
public:
Derived2(int x, int y);
};
How do I get the 2D array to accept and afterwards correctly display the objects in that array?
Whenever I try
Derived[x][y] = new Derived2(x,y);
It just doesn't seem to work and I really think I'm stuck on this for a while :(