C语言中文网中 C++静态成员函数这节,出现C++ 无法将参数1 从“const char[5]”转换为“char”错误,最后自己解决了,这里记录一下,希望同样问题的同学或者以后方便查询。
事例,代码如下
#include <iostream>
using namespace std;
class Student {
public:
Student(char *name, int age, float score);
void show();
public: //声明静态成员函数
static int getTotal();
static float getPoints();
private:
static int m_total; //总人数
static float m_points; //总成绩
private:
char *m_name;
int m_age;
float m_score;
};
int Student::m_total = 0;
float Student::m_points = 0.0;
Student::Student(char *name, int age, float score) : m_name(name), m_age(age), m_score(score)
在C++静态成员函数的学习过程中,遇到一个编译错误:无法将参数1从"const char[5]"转换为"char"。通过分析错误提示,了解到这是一个非法转换的问题。在VS2017上运行时显示此错误。解决方法是根据编译器提示进行修改,避免这种类型不匹配的情况。这是C与C++的一个关键区别。
最低0.47元/天 解锁文章
205

被折叠的 条评论
为什么被折叠?



