【发布时间】:2016-11-23 04:35:56
【问题描述】:
我这样写代码
class A{
// ...
public:
insert(int key, char* contents){ ... }
}
想用
A.insert(1, "hellow world");
但不允许从字符串文字转换为 char*
怎么可以这样使用?
【问题讨论】:
-
只使用 c++ 字符串字面量
我这样写代码
class A{
// ...
public:
insert(int key, char* contents){ ... }
}
想用
A.insert(1, "hellow world");
但不允许从字符串文字转换为 char*
怎么可以这样使用?
【问题讨论】:
字符串文字是const char*。
class A{
// ...
public:
insert(int key, const char* contents){ ... }
}
// ...
A.insert(1, "hello world");
【讨论】: