C++基础:共享方法如何识别对象,*this

编译器对类的识别顺序:
1.识别类名;

2.识别数据成员;

        3.识别函数,改写函数;

什么是*this:

        1.代表当前对象;
        2.当函数被调用时,this指针会被隐藏插入;

改写方法:

        1.函数改写:
改写前:

void RegisterGoods(char name[],int amount,float price);
{
strcpy(Name,name);
Amount = amount;
Price = price;
}
改写为:

void RegisterGoods(CGoods *const this,char name[],int amount,float price);
{
strcpy(this->Name,name);
this->Amount = amount;
this->Price = price;
}
 2.调用改写:
改写前:c1.RegisterGoods("C++",10,12);
改写为:c1.RegisterGoods(&c1,"C++",10,12);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值