, , (. base class). , , , (. derived class).
. , , , , . . , . , , , . . (, ), . , , .
3.³
( ) - () , - , . , : , , .
. , , -. . , Java, , , , . (, , Python), .
, . ( . pure virtual) . , , . ( , ). , , , .
, , . . : , , , , . , .
|
|
4. '
, ' ( ) , . ', , , ' , .
C + +: C + + ' ( ). , (virtual), ( ). , ', OP.
OP: Object Pascal ' virtual dynamic ( ). override ( ). OP , .
Java: Java ', final. Գ . Java . , Java ', C + + ', - : C + + , Java -
: ϳ ' . Object Pascal, , . .
5.
- , . - . ( [1]) . , , . , .
, (, Delphi), . , (, Java), . , , , , , .
|
|
, .
:
. . . C++. , , Python . UML.
, - . , C++ (Java, C# .), . . , - , , , , , :: .
, .
- (C#, Java, Delphi .) - . , -.
7. . . .
́ ́ ́ (. exception handling) , (), () . : .
:
. () . ():
... //
...
() 2
...
1
... // 1
2
... // 2
... //
void func(){ try { throw 1; } catch(int a) { cout << "Caught exception number: " << a << endl; return; } cout << "No exception detected!" << endl; return;}
, , . , , , , , . , . - ( , ), : , , . , ( ). .
|
|
, (), (, , ). , , . , , .
, , - , ( , , ). . , .
8. . .
C++ catch. - try- , catch , .
Catch- : catch, , ( ), . catch-, . catch- pushOnFull popOnEmpty main() :
catch- ; pushOnFull, popOnEmpty. , . ( 19 , : .) , - pop() iStack popOnEmpty, . cerr, main() errorCode89.
catch- return, ? , catch- . return main(). catch- popOnEmpty , main() 0.
|
|
, C++ : , , . - pop(), .
, , : , .
, . , , , .
, . : .
, . , - , .
9. .
unexpected.
, , . , , , .
,
catch (int) { }unexpected . , , . : . unexpected , .
#include <exception>
using namespace std;void my_unexpected_handler() { throw 1; }void f() throw(int) { throw 1L; // ! -- ** }int main() { set_unexpected(my_unexpected_handler); try { f(); } catch (...) { } return 0; }f , . my_unexpected_handler. . , , , , .
int my_unexpected_handler main .