c++ - Converting a string constant to char
问题描述
I have a class named Player but when building a constructor like the one below, I got a warning that read: ISO C++ forbids converting a string constant to 'char'. Can anyone tell me what this means and how I can fix it?
class Player
{
public:
Player(char * firstN = "", char * lastN = "");
};
解决方案
ISO C++ 禁止将字符串常量转换为 'char'
我怀疑编译器是这么说的。它可能会说“ISO C++ 禁止从字符串常量转换为 char*”。它们是有区别的。
谁能告诉我这是什么意思
这意味着您正在尝试使用字符串常量初始化指向 char 的指针。正如错误消息所解释的,这是无法完成的,因为字符串常量不能隐式转换为这种类型。
我该如何解决?
您可以将参数类型更改为const char*
. 字符串常量隐式转换为该类型。
推荐阅读
- angular - 离子重试发布信息策略/策略
- mysql - 在mysql中的同一张表中找到许多匹配的一行
- javascript - 如何在javascript中将一个数组的现有数组对象替换为另一个数组
- jupyter-lab - 如何“查找和替换”文本?
- powershell - 如何使用 PowerShell 处理输出的 diskpart 命令
- javascript - 如何处理 Ember Js Handlebars 中的对象数组
- maven - maven javadoc插件抛出异常退出代码:1 - javadoc:错误 - 无法读取输入长度= 1
- json - Cumulocity JSON 通过 MQTT / 测量和错误主题
- c# - 解决方案中的 .NET 项目应该生成一个 exe,但只生成一个安装文件和快捷方式
- r - 重塑然后折叠数据框