- 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(); }
this指针
最新推荐文章于 2024-04-08 08:04:23 发布