this指针

  • 7.8指针
  • Int a=10;
  • Int b=20;
  • Int *p=&a;
  • P=>&a;
  • *p=>a;
  • P=&b;
  • *p=b;
  • 二级指针
  • 一级指针储存用二级指针
  • Char a=10,b=20;
  • Char c=a&b;
  • Char *cp=&a;
  • Char &x=a;à表示引用;
  • 引用无二三级之说;
  • 类型是设计的产物
  • This 指针
  • 编译器针对程序员自己设计的类型分三次编译:
  • 第一:识别和记录类体中属性的名称,类型和访问限定,与属性在类体中的位置无关。
  • 第二:识别和记录类体中函数原型(返回类型+函数名+参数列表),形参的默认值,访问限定。不识别函数体。
  • 第三:改写在类中定义函数的参数列表和函数体,改写对象调用成员函数的形式;
    #include<stdio.h>
    #include<assert.h>
    #include<iostream>
    #include<string.h>
    
    class CGoods//设计类型
    {
    private:
    	char Name[21];
    	int Amount;
    	float Price;
    	float Total_value;
    public:
    	//void RegisterGoods(CGoods *this,conts char*,int,float);//输入数据
    	void RegisterGoods(const char*, int, float);
    	//void CountTotal(CGoods *this)//计算商品总价值
    	void CountTotal()
    	{
    		Total_value = Amount * Price;
    	}
    	//void GetName(CGoods *this,char name[])//读取商品名
    	void GetName(char name[])
    	{
    		strcpy_s(name, 20, Name);
    	}
    	//int GetAmount(CGoods *this)//读取商品数量
    	int GetAmount()
    	{
    		return Amount;
    	}
    	//float GetPrint(CGoods *this)//读取商品单价
    	float GetPrice()
    	{
    		return Price;
    	}
    	//float GetTotal_value(CGoods *this)//读取商品总价值
    	float GetTotal_value()
    	{
    		return Total_value;
    	}
    };
    //void CGoods::RegisterGoods(CGoods *this const char* name, int amount, float price)
    void CGoods::RegisterGoods( const char* name, int amount, float price)
    {
    	strcpy_s(this->Name, 20, name);
    	this->Amount = amount;
    	this->Price = price;
    }
    int main()
    {
    	CGoods c1, c2;
    	c1.RegisterGoods("iphone", 10, 6800);
    	//RegisterGoods(&c1,"iphone", 10, 6800);
    	c1.CountTotal();
    	c2.RegisterGoods("huawei", 12, 7800);
    	//RegisterGoods(&c2,"huawei", 12, 7800);
    	c2.CountTotal();
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值