.


:




:

































 

 

 

 


, , ,




10. , , ,

11. , , ,

12. , , ,

13. , , ,

14. , , ,

15. , , ,

3.

' . .

. '- -.

.

.

', '. ', , . , , .

:

1)³ , 䳺 , , , , .. ' , TGroup (TDeskTop, TWindow, TDialog) Turbo Vision ' , TWindowObject OWL.

2), .

3), , .

4) (, , , ).

. . : ' TCollection Turbo Vision ' STL C++ (, , ).

쳺 , , ' , , .

( , ) ' ( /), .

.

1. ' . , ' ,

class TWindowDialog: public TGroup

{

protected:

TInputLine input1;

TEdit edit1;

TButton button1;

/* */

};

C++Builder.

2. - last TObject*, ' ', . ' next TObject*, . Turbo Vision.

3. ' TItem:

struct TItem

{TObject* item;

TItem* next;};

item ', . last TItem *, ' TItem.

, ' TObject owner TGroup*, .

.

, :

1) void Insert(TObject* p);

.

2) void Show();

.

:

1) int Empty();

, .

2) TObject* Delete(TObject* p);

, '.

3) void DelDisp(TObject* p);

'.

'

, " ". , " ", . ' , " ". , " - ", . ' ' , .

.

䳿 .

For all { 䳿}

, , . , , , .

-, 䳿 ', . Show.

, 䳿, ', . , .

:

typedef void(*PF)(TObject*,< >);

' TObject TObject*, ', 䳿.

- ' :

void TGroup::ForEach(PF action,< >);

action- ' - , ;

, , .

.

PF pf=myfunc;

, int, :

gr.ForEach(pf,25);

gr-'-.

.

, . , ' .

++ , . ' , ' - .

' 䳿 ' . '.

++ RTTI (Run-Time Type Idendification)- . ֳ Borland C++ ( 4.0 ).

' typeid, <typeinfo.h>.

typeid:

typeid (')

typeid ('_)

typeid ' type_info.

type_info == != .

name() ' .

. typeid ', . ' , , . typeid ( ), .

.

1.

#include<iostream.h>

#include<typeinfo.h>

class Base{

virtual void f(){};

//

};

class Derived: public Base{

//

};

void main()

{int i;

Base ob,*p;

Derived ob1;

cout<<typeid(i).name(); // int

p=&ob1;

cout<<typeid(*p).name(); // Derived

}

2.

// .

void WhatType(Base& ob)

{cout<< typeid(ob).name()<<endl;

}

void main()

{

Base ob;

Derived ob1;

WhatType(ob); // Base

WhatType(ob1); // Derived

}

3.

// .

void main()

{

Base *p;

Derived ob;

p=&ob;

if(typeid(*p)==typeid(Derived)) cout<<p ' Derived;

}

typeid(*p), p=NULL, bad_typeid

.

1. 2 .

, , , . - , TObject, 񳺿 .

2. - - .

3. , ', ( ).

4. , , '-, .

.

1.- 2, ' . , 1

TObject (. )

 
 

 


(. ) ϳ ( )

 

 





:


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


:

:

, , 1:10
==> ...

1738 - | 1682 -


© 2015-2024 lektsii.org - -

: 0.025 .