// 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)
你传入的是字符串常量本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报