c++中关于参数是字符数组时的情况

在论坛里面看到一个c++课本上完全写下来的程序。但是说编译时有问题。正好我也有这本课本,回去尝试了,确实,报错了。找了一会儿,最后知道了原因。其实学习c的时候知道这部分知识,在这里就是没想起来。不过也无关紧要了,已经过时的东西,以后估计也不会碰到了吧。

代码如下:(注释)

#include "pch.h"
#include <iostream>
#include<string>
using namespace std;
void xiaoming(string a, double b);
void xiaowang(char a[], double b);
int main()
{
	//CGoods  car1("夏利", 20, 332.30);     这里会报错误,错误类型:参数类型不匹配
	const char a[] = "luoyuanyi";
	xiaoming("夏利", 2);       //难道这里传递的是指针吗?或者是引用?要不然不可能说用const
	 //xiaowang("夏利", 3);       这里和上面同样的道理
	return 0;
}
void xiaoming(string a, double b) {
	cout << a << endl;
	cout << a.size() << endl;
	
}
void xiaowang(char a[], double b) {
	
}
//头文件如下:
#ifndef PCH_H
#define PCH_H
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
class CGoods {
private:
	char Name[21];
	int Amount;
	float Price;
	float Total_value;
public:
	CGoods() {
	}
	CGoods(char a[], int b, float c)
	{}
	CGoods(char[],float){}
};
#endif

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值