// 106.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
using namespace std;
//定义rect类
class rect {
int length;
int width;
int area;
public:
rect(int l = 1, int w = 1)
{
length = l;
width = w;
area = length * width;
}
void show_rect(char* name)
{
cout << name << ":" << endl;
cout << "length=" << length << endl;
cout << "width=" << width << endl;
cout << "area=" << area << endl;
}
};
//测试使用rect类
void main()
{
//用rect类创建对象
rect a;
rect b(2);
rect c(2, 3);
//调用对象的函数显示对象中的数据
a.show_rect("a");
b.show_rect("b(2)");
c.show_rect("c(2,3)");
}
为什么函数的形参列表是指针我主函数中传入的却是个字符串,如下图
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 浪客 2022-03-26 17:54关注
void show_rect(const char* name)
你传入的是字符串常量本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度