【发布时间】:2011-02-11 07:10:12
【问题描述】:
我想在构造函数中使用 ASCII 代码初始化一个静态 const char 数组,这是我的代码:
class Card
{
public:
Suit(void)
{
static const char *Suit[4] = {0x03, 0x04, 0x05, 0x06}; // here's the problem
static const string *Rank[ 13 ] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'}; // and here.
}
但是我得到了很多错误说明
'initializing' : 无法从 'char' 转换为 'const std::string *'
'initializing' : 无法从 'int' 转换为 'const std::string *'
请帮助我!非常感谢。
【问题讨论】:
-
从
char转换为const std::string*是您最不必担心的事情 -
Suit(void)不是构造函数。您可以通过声明一个没有返回类型且与类同名的函数来声明构造函数。 -
此外,字符串不应用作通用变量类型。此处推荐枚举。