用C语言的编写方式来谈对C++中隐藏指针this的认识
首先我们来看一组C++的程序
#include<iostream>
using namespace std;
class CGoods
{
public:
/所给参数一样 前后都是Name///
void RegisterGoods(char Name[],int Amount,float Price)
{
strcpy(this->Name,Name);
this->Amount=Amount;
this->Price=Price;
}
///这段代码和以上的可以进行替换,主要看参数是否一样(这是参数不一样的)///
void RegisterGoods(char name[],int amount,float price)
{
strcpy(name,Name);
amount=Amount;
price=Price;
}
/
void CountTotal(void);
void GetName(char name[])
{
strcpy(name,Name);
}
int GetAmount(void);
float GetPrice(void);
float GetTotal_value(void);
private:
char Name[21];
int Amount;
float Price;
float Total_value;
};
/*
void CGoods::RegisterGoods (char name[],int amount,float price)
{
strcpy(Name,name);
Amount=amount;
Price=price;
}
*/
void main()
{
char name[21];
CGoods c1,c2;
c1.RegisterGoods ("c++",15,30);
c2.RegisterG