.


:




:

































 

 

 

 


Void get_info(int _x,int _y)




{

x=_x;

y=_y;

}

void putinfo(int &xx,int &yy)

{

xx=x;

yy=y;

}

};

Void main()

{

Coord arg;

coord*p=&arg;

arg.get_info(10,5);// . -

Int col,row;

p->putinfo(col,row);// -> -

}

18

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

- ()

_ (_:: *_)();

, . *, à*.

#include <stdio.h>

class A

{

public:

void f1()

{

puts (!);

}

void f2()

{

puts (!);

}

};

void main()

{

void (A::pf)()=&A::f1;

/* pf - f1()*/

A q; //q

A*pA=&q; // q

(q.*pf)(); / q.f1();

pf=&A::f2; //B pf f2().

(q.*pf)(); //q.f2();

(pAà*pf)(); /* q. pf f2(). f2() q, .. q.f2()*/

}

this

() , , . ++ this. , , , . this (return this) (return *this) .

this .

 

-

, , , . . -: , , , , .

 

, . , . . . , const, volatile, static, virtual.

,

_ ()

{

}

.. .

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

class coord

{

float x, y;

public:

coord (float a, float b)

{

x=a;

y=b;

}

};

void main ()

{

coord w (2.5, 12.3);

}

w coord . b 2.5 12.3.

, . (:) - ( ), .

.

class coord

{

const float x,y;

public:

coord(float a, float b):x(a),y(b)

{

}

};

void main()

{

coord w(2.5, 12.3);

}

- , . , ( ) .

.

class coord

{

const float x,y;

public:

coord(float a, float b):x(a),y(b)

{

}

};

class map

{

coord w;

public:

map (float_x, float_y):w(_x,_y)

{

}

};

void main ()

{

map q(1Ø,15); // q map // x(a), x(b)

}

.

(const _ &) (_ &).

_ (const _&__)

_ (_&__).

, .

, ( ).

( ), . . , .

#include <stdio.h>

class point

{

float x,y;

public:

point (float a, float b)

{

x=a;

y=b;

}

point (const point &src)

{

x=src.x;

y=src.y;

}

};

void main()

{

point v(2.43, 8.1);

point w=v;

}

v point , -. v.x=2.43, v.y=8.1.

w point . src v. w.x=2.43, w.y=8.1.

! , private. , , . - .

 

- operator=. const _& _&. :

_& operator=(const _ &x)

_& operator=(_ &x).

, const - , .

, . , , . , :

x=y=b;

, . . , .

.

class comp

{

float Re, Im;

public:

comp (float a, float b):Re(a),Im(b)

{

}

comp& operator=(const comp& src)

{

Re=src.Re;

Im=src.Im;

return *this;

}

comp (const comp& x)

{

Re=x.Re;

Im=x.Im;

};

void main()

{

comp x(1,2), y(-Ø.5,1.25);

comp z=x; //

comp v,w; //

v=w=y; // operator=()

}

, v=w=y;

= - operator=(). ,

const comp& src operator=().

w this - . , return*this w.Re=- Ø.5; w.Im=1.25.

operator=(). w, v this . .

return*this, , operator=() .

! , operator=() private.

 

. , , - (~). , .

~_()

:

1) ;

2) ;

3) ;

4) const, volatile, static.

 

, .

:

1) ;

2) ;

3) delete , .

, _. ~ _ ();

, s. ~ tree (); s tree.

this > ~ tree (); tree, tris.

 

 

(int, long, char .) . . , .

 





:


: 2015-11-05; !; : 657 |


:

:

,
==> ...

1742 - | 1610 -


© 2015-2024 lektsii.org - -

: 0.03 .