/*
*测试函数参数传递机制
*/
class CRect {
public:
int height;
int widht;
CRect() {
height = 0;
widht = 0;
}
CRect(int height, int widht) {
this->height = height;
this->widht = widht;
}
};
//(1)传址调用(传指针)
int RectAreaPoint(CRect *rect) {
int result = rect->height * rect->widht;
rect->height = 20;
return result;
}
//(2)引用传递
int RectAreaRefer(CRect &rect) {
int result = rect.height * rect.widht;
rect.height = 30;
return result;
}
//(3)传值调用
int RectArea(CRect rect) {
int result = rect.height * rect.widht;
rect.height = 40;
return result;
}
//测试代码逻辑
void testPoint() {
CRect rect(10, 10);
cout << "面积:" << RectAreaPoint(&rect) << endl;
cout << "面积:" << RectAreaRefer(rect) << endl;
cout << "rect.height:" << rect.height << endl;
cout << "面积:" << RectArea(rect) << endl;
cout << "rect.height:" << rect.height << endl;
}
//测试结果
面积:100
面积:200
rect.height:30
面积:300
rect.height:30
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有