I've created a class, called vir, with a function move:
class vir
{
public:
vir(int a,int b,char s){x=a;y=b;sym=s;}
void move(){}
};
(It's derived from a class with variables int x, int y, and char sym) I have derived a class from this, called subvir:
class subvir:public vir
{
public:
subvir(int a,int b,char s){x=a;y=b;sym=s;}
void move();
};
subvir::move()
{
x++;
return;
}
And then I created an array of vir, and put a subvir into it
subvir sv1(0,0,'Q');
vir vir_RA[1]={sv1};
But when I try to use sv1.move():
vir_RA[0].move();
It uses the vir move ({}) rather than the subvir move ({x++}). I have tried making sv1 a vir and vir_RA a vir, and it works, and it also works when I make them both subvir, but I need them to be different. I tried making vir::move() a pure virtual, but then I get an error substantiating the array. Does anyone know how I can get move() to work when I use it from the array?