, - . . . .
.
class Basis
{ int a,b;
public:
Basis(int x,int y){a=x;b=y;}
};
class Inherit:public Basis
{int sum;
public:
Inherit(int x,int y, int s):Basis(x,y){sum=s;}
};
: , - ( ), . , .
: , -, .
, .
, . , , .
() . , virtual.
.
class base
{
public:
virtual void print(){cout<<\nbase;}
...
};
class dir: public base
{
public:
void print(){cout<<\ndir;}
};
void main ()
{
base B,*bp = &B;
dir D,*dp = &D;
base *p = &D;
bp >print(); // base
dp >print(); // dir
p >print(); // dir
}
, , .. , .
, , , ( ) , .
-.
. , ( ) , virtual .
, . , , .
, () .
, :
|
|
virtual _ (__) = 0;
. . .
, . . . . . , .
.
class Base{
public:
Base(); //
Base(const Base&); //
virtual ~Base(); //
virtual void Show()=0; //
//
protected: //
private:
// ,
};
class Derived: virtual public Base{
public:
Derived(); //
Derived(const Derived&); //
Derived(); //
virtual ~Derived(); //
void Show(); //
//
//
protected:
// private,
private:
//
};
, . , . .
. . , , . .
: . , Draw, : TTriangle, TCircle, TSquare. TGraphObject. ,
TGraphObject . Draw () TGraphObject, TTriangle, TCircle, TSquare.
, . - , ++, , , . , TGraphObject, . . Draw , , . Draw TGraphObject , Draw TGraphObject . , -, Draw .
|
|