.


:




:

































 

 

 

 





++ 4 :

  1. ( )
  2. , .
  3. return. , return .

class A

{ char *p;

int size;

public:

A(int s, const char *c)

{

p=new char(size s);

strcpy(c);

}

~A()

{

delete []p;

}

A & operator=(const A &a)

{

if(this!=&a)

{

delete []p;

p=new char[size=a.size];

strcpy(p,a.p);

}

return *this;

}

A(const A&) //

{

p=new char[size=a.size];

strcpy(p,a.p);

}

}

void main()

{

A a(10, String 1),b(12, String 2);

...

a=b;

 

A c(20, String 3);

A d=c; // ,

}

, .


, , , , .

//

class XClass

{

OClass o;

public:

XClass();

XClass(const XClass f):obj(a.obj) {}

~XClass();

const XClass & operator=(const XClass f);

};

, (virtual).

 

 

.

:

1. , , , . , , , . , .

2. , , , , . , . , , . , .

. , . , .

, clone Object, . Cloneable, clone . -, , , ,

PrototypelF Cloneable, . , , PrototypelF, Cloneable.

, , . , , .


. . .

complex . , double, , . . , :

class matrix {

double m[4][4];

public:

matrix();

friend matrix operator+(const matrix&, const matrix&);

friend matrix operator*(const matrix&, const matrix&);

};

. , .. , .

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

-

T::T(const T&){/* */}

,

-

-

-

, . .

, , , , :

date date2 = date1;

, :

- - , , ;

- - , , return , .

:

- dat2 ;

- ;

- , , .

-:

- dat1 ;

- ;

- - return.

, -, . , . - -:

class string

{

char *Str;

int size;

public:

string(string&); //

};

string::string(string& right) //

{ //

s = new char[right->size];

strcpy(Str,right->Str);

}

, - , , .

. , , .. , , , .

, . .

x = 2; // x 2cond = x < 2; // cond true, x 2, // false3 = 5; // , 3

. . , , .

int x = 0;x = 3;x = 4;x = x + 1;

x 0. x 3, 4 5. -, . , . x + 1, x 4. x + 1 5. (, , ) x 5.

. . , :

z = (x = y + 3);

x z y + 3.

. , ++ : ++ ( ) -- ( ). : . .

int x = 0;++x;

x 1.

--x;

x 0.

int y = ++x;

x . ++ x, .. y 1.

int z = x++;

. x 1. x 2. . , z 1. , , .

( ++), " ". , :

x = x + 5;y = y * 3;z = z (x + y);

++ :

x += 5;y *= 3;z -= x + y;

.. oper= , oper, oper. , .

 

 






:


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


:

:

, .
==> ...

1635 - | 1565 -


© 2015-2024 lektsii.org - -

: 0.018 .