Int **s //二级指针
& 与,地址,引用
int main()
{char a=10,b=20;
char c=a&b;
char* cp=&a;
char& x=a; //引用:不存在空引用,必须给予初始化;不存在引用的引用(没有二级引用);
x=’a’;
a=’z’;
}
类型是设计的产物
编译器针对程序员自己设计的类型分三次编译:
- 识别和记录类体中属性的名称,类型和访问限定,与属性在类体中的位置无关。
- 识别和记录类体重函数原型(返回类型+函数名+参数列表),形参的默认值,访问限定。不识别函数体。
- 改写在类中定义函数的参数列表和函数体,改写对象调用成员函数的形式。
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
class CGoods
{
private:
char Name[20];
int Amount;
float Price;
float Total_value;
public:
//void RegisterGoods(CGoods *this,const 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()//读取商品数量
{
return Amount;
}
//float GetPrint(CGoods *this)
float GetPrice()//读数商品单价
{
return Price;
}
//float GetTotal_value(CGoods *this)
float GetTotal_value()//读取商品总价值
{
return Total_value;
}
};//最后的分号不能少,这是一条说明语句
//void CGoods::RgisterGoods(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);
//RgisterGoods(&c1,"iphone",10,6800);
c1.CountTotal();
c2.RegisterGoods("huawei", 12, 7800);
//RgisterGoods(&c1,"huawei",12,7800);
c2.CountTotal();
}