.


:




:

































 

 

 

 


. . . ,




(virtual functions). ,

virtual, , (overridden), . , .

 

(polymorphism = ). , , , . - ,

 

:

● , - , , , ;

● - , .

 

class Vehicle

{

public:

virtual float getMaxExtraWeight () const { return 0.0f; }

};

 

 

. VPTR VTABLE. . .

VPTR (virtual functions table pointer) . . , - VPTR VTABLE File:

 

, - VPTR Directory:

 

VPTR

. . , , vptr , .

, :

 

- :

; vptr FilesystemEntry

008B1225 mov dword ptr [eax],offset FilesystemEntry::`vftable' (8C6338h)

 

- :

;

00054689 call FilesystemEntry::FilesystemEntry (516D1h)

0005468E mov dword ptr [ebp-4],0

00054695 mov eax,dword ptr [ebp-14h]

; vptr Directory

00054698 mov dword ptr [eax],offset Directory::`vftable' (74978h)

 

pRootDir->show(std::cout, 0);

; ( )

00A0C999 push 0

00A0C99B mov eax,dword ptr [__imp_std::cout (0A1D364h)]

00A0C9A0 push eax

; ecx - (pRootDir)

00A0C9A1 mov ecx,dword ptr [ebp-18h]

; edx

00A0C9A4 mov edx,dword ptr [ecx]

; eax 8 .

; 32- 2

00A0C9A9 mov eax,dword ptr [edx+8]

;

00A0C9AC call eax

 

 

. . override final. .

:

● ;

● ;

● const ( this);

● .

 

, .

 

, , .

 

, , const - , . , , - ( )

, , , . , ++11 override . , . , .

 

, ++11 final, . , :

(covariance) - . , , , . ,

.

- .

 

 





:


: 2016-07-29; !; : 722 |


:

:

, .
==> ...

1919 - | 1717 -


© 2015-2024 lektsii.org - -

: 0.016 .