.


:




:

































 

 

 

 





- . , . , , - . .

- ()

1980 Smalltalk-80, - Xerox. - . .

- : , , , .

, , . .

( ).

- .

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

- , .

- , .

- () . , , .

- , . , , , .

, , , , .


3. 3. - ++

, .

(encapsulation). . , , , , . . , , .

:

class _ {_};

( member) (-, ), ( , -), .

, . .

, .

private

public .

protected ( ).

private. .

class CStr

{

char * s;

int len;

public:

CStr () {len=0; s=new char; *s=\0;}

CStr (char *);

char * get_str() {return s;}

int get_len(){return len;}

}

, (inline). . , .

CStr::Cstr(char * st)

{len=strlen(st); s=new (char[len+1]); strcpy(s,st); s[len]=\0;}

 

, .

_ _ [( )];

, . ( , ). . , void. . , . .

Str s1,s2;

CStr s3(aaa);

, .

.

cout<<s1.get_str();

, ->.

, , , , .

, , , . ~ . , . , . , . , , .

Str::~Csrt(){delete [] s};

++ , . . (-) :

- , ;

- ;

- ( =), , static;

- , , , , , .

bool operator ==(CStr & s1, CStr& s2)

{

if (s1.get_len()==s2.get_len())

{ int i=0;

while (i<s1.get_len() && s1.get_str()[i]==s2.get_str()[i]) i++;

if (i==s1.get_len()) return true;

}

return false;

}

 

, . . friend . . . .

friend ostream& opertor << (ostream& out, CStr& st)

{return out<<st.s;}

, .

 

, ( , ) (, ), . ( ). ++ .

-

lass : [private| protected | public]

private ( private). Public - . Protected - protected, private.

class CBStr: public CStr

{

public:

CBStr(char* a);

CBStr(char a);

};

private, public. ,

class CBStr: public CStr

{

public:

Str::s;

.

};

, , protected.

. , . .

CBStr::CBStr(char* a):CStr (a)

{

if (!binarnost(a)) empty();

}

binarnost() , empty () , .

void CStr::empty()

{ if (*s!= '\0') { len = 1; delete []ch; ch = new char; ch[0] = '\0';} }

 

protected, .

, .

- . , , .

- , , .

 

 





:


: 2016-11-12; !; : 355 |


:

:

, .
==> ...

1547 - | 1388 -


© 2015-2024 lektsii.org - -

: 0.019 .