_ * const this
const _ *const this
, const . , , const. const- . , .. - .
, . , " ". - (const). , .
void dat::put() const
{... }
:
const class a{...} value;
1) ;
2) .
, .
\\ .
const Point2d d(5,4);
double mod() const
{
return sqrt(x*x+y*y);
}
this :
const _ const *this;
, , const. , . , , .. .
this
- , , . this
_ *const this = _
this . this , . . this . , - this . , add complex , :
void complex add(complex ob)
{
this->re=this->re+ob.re;
// *this.re=*this.re+ob.re
|
|
this->im=this->im+ob.im;
}
, , this.
, add .
complex& complex add(complex& ob)
{
re=re+ob.re;
im=im+ob.im;
return *this;
}
"this".
- - , , . :
class x
{
int m;
public:
int readm()
{
return m;
}
};
x aa;
x bb;
void f()
{
int a = aa.readm();
int b = bb.readm(); //...
}
readm() m aa.m, - bb.m.
, -, . this. x this x* this , , -. this , .
this , .
int a;
int *pa;
pa=&a;
*pa=10; //
//
void f();
void(*pf)();
pf=f; // .
(*pf)(); // f
pf(); //
class Point2D
{
public:
double x,y;
double mod() const;
};
Point2D a(3,5);
double *pd;
pd=&a.x;
*pd=10;
pd=a.y;
*pd=15;
++ .
double Point2D::*pd;
double (Point2D::*pf)()const;
.
pd=&Point2d::x; //
pf=&Point2D::mod; //
, , , .
:.* ->*
Point2D a(2,3), *pa=&a;
Point2D b(3,4), *pb=&b;
a.*pd=10; //a.x=10
pa->*pb=10;
b.*pb=10;
pb->*b=12; //pb->x=12
cout<<(a.*pf)();
, .