.


:




:

































 

 

 

 





poly () morphos () . - (.. , ) - , . , .

, .. . - - , , , . , (, , , , , ..) Draw, .

, , .

3.5.1

, , . , -.

C++ , . , , , . . 3.9 , -.

I class Parent { public:

double Fl(double x) { return x*x; }

double F2(double x) { return Fl(x)/2; }

class Child: public Parent { public:

double Fl(double x) { return x*x*x; } };

void main() {

Child child;

cout child.F2(3) end1;

}

3.9. .

Parent - Fl F2, F2 , El,. Child, Parent, F2, Fl. 13.5 4.5. , child. F2 (3) Parent::F2, Parent::F1, Child::F1, .

C++ . 3.10 .

jclass classNamel {

// -

virtual returnType functionName(< >);

};

class className2: public classNamel {

// -

virtual returnType functionName(<cmicoK >);

};

3.10. .

F1 Parent Child, . 3.11 .

class Parent {

public:

virtual double F1(double x) { return x*x; }

double F2(double x) { return Fl(x)/2; }

};

class Child: public Parent { public:

virtual double F1(double x) { return x*x*x; }

);

void main() {

Child child;

cout child.F2(3) endl;

}

3.11. .

13.5. child. F2 (3) Parent:: F2, Child::F1.

, . , ( ) . - , . C++ , , , .

, , - , virtual, .

. - . . .





:


: 2015-10-01; !; : 565 |


:

:

80% - .
==> ...

1772 - | 1624 -


© 2015-2024 lektsii.org - -

: 0.011 .