this指针

this指针
this指针reference

this指针
在每一个成员函数中都包含一个常量指针,我们称其为 this 指针。this 是 C++ 的一个关键字,this 指针指向调用本函数的对象,其值为该对象的首地址。通过该指针,我们可以在成员函数的函数体内访问对象。
#include
using namespace std;

class book
{
public:
book(){price = 0.0; title = NULL;}
void copy(book &b);

void display();
private:
double price;
char * title;
};

void book::copy(book &b)
{
//我们用 this 指针先判断被拷贝的对象的引用是否是调用该函数的对象自身,如果

this指针最先出现在Python成神之路

版权声明:
作者:cc
链接:https://www.techfm.club/p/20895.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>