基类指针数组用来指向派生类
在主函数定义了一个基类指针数组用来指向派生类,但是我要去调用派生类的虚函数的时候调用不了,麻烦大家帮忙看下if(arr[n]->InStr3_No==0)
arr[n]->CcCal2();
else
arr[n]->CcCal3();
class Gate{
public:
Gate();
/*void gate(int,int);
void gate(int,int,int);*/
void gate(int,int,int,int);
virtual void CcCal2()
{ }
virtual void CcCal3()
{ }
void ChangeNextIn( );
void Push(Queue &qu);
void min2(int &y,int x1,int x2);
void min3(int &y,int &x1,int &x2,int &x3);
void add2(int &y,int &x1,int &x2);
void add3(int &y,int &x1,int &x2,int &x3);
Gate *Pnext1,*Pnext2,*Pnext3;
int InStr1_No,InStr1_CC0,InStr1_CC1;
int InStr2_No,InStr2_CC0,InStr2_CC1;
int InStr3_No,InStr3_CC0,InStr3_CC1;
int OutNo,OutNewCCO,OutNewCC1,OutOldCCO,OutOldCC1;
};
class NotGate:public Gate
{
public:
virtual void CcCal2()
{
OutNewCCO=InStr1_CC1+1;
OutNewCC1=InStr1_CC0+1;
}
};
class AndGate:public Gate
{
public:
virtual void CcCal2()
{
min2(OutNewCCO,InStr1_CC0,InStr2_CC0);
add2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
virtual void CcCal3()
{
min3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
add3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class OrGate:public Gate
{
public:
virtual void CcCal2()
{
add2(OutNewCCO,InStr1_CC0,InStr2_CC0);
min2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
virtual void CcCal3()
{
add3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
min3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class OrNotGate:public Gate
{
public:
virtual void CcCal2()
{
min2(OutNewCCO,InStr1_CC0,InStr2_CC0);
add2(OutNewCC1,InStr1_CC1,InStr2_CC1);
}
virtual void CcCal3()
{
min3(OutNewCCO,InStr1_CC0,InStr2_CC0,InStr3_CC0);
add3(OutNewCC1,InStr1_CC1,InStr2_CC1,InStr3_CC1);
}
};
class XorGate:public Gate
{
public:
virtual void CcCal2()
{
min2(OutNewCCO,InStr1_CC0+InStr2_CC0,InStr1_CC1+InStr2_CC1);
min2(OutNewCC1,InStr1_CC0+InStr2_CC1,InStr1_CC1+InStr2_CC0);
}
};
class Dtri:public Gate
{
public:
virtual void CcCal2()
{
add3(OutNewCCO,InStr1_CC0,InStr1_CC1,InStr2_CC0);
add3(OutNewCC1,InStr1_CC0,InStr1_CC1,InStr2_CC1);
if(OutNewCCO<1000)
OutNewCCO=OutNewCCO-1;
if(OutNewCC1<1000)
OutNewCC1=OutNewCC1-1;
}
};