如何使用在 C++ 的类主体中的类 def 中定义的字符数组数组
How do I use an array of character arrays defined in the class def in the class body in C++?
当我的设置如下所示时,如何使用字符数组数组:
在课堂上。
namespace foomaker
{
class foo
{
const char **mystringarray;
bool ipitythefoo ();
};
}
在福.cpp #include 类.h
namespace foomaker
{
bool foo::ipitythefoo()
{
*mystringarray[] = {"Mr. T","Gold Chains","Mohawks"};
return false;
};
}
编译器抛出错误:
1>.foofactory.cpp(5) : error C2059: syntax error : ']'
1>.foofactory.cpp(5) : error C2143: syntax error : missing ';' before '{'
1>.foofactory.cpp(5) : error C2143: syntax error : missing ';' before '}'
或者这甚至可能吗?
无法为此使用字符串、映射或向量。
最终结果是,这将适用于我需要通过位置编号获取的错误字符串。错误字符串特定于此类。
谢谢
你想
做什么是不可能的。您正在尝试重新初始化数组,但这无法完成。也许,鉴于您的用例是针对错误字符串的,您可以执行以下操作:
bool foo::ipitythefoo()
{
static const char* actualstringarray[] = {"Mr. T","Gold Chains","Mohawks"};
*mystringarray = actualstringarray;
return false;
};
但是,一开始就static
一系列错误字符串会更有意义。
相关文章:
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- C++编程从外部文本文件定义数组大小
- 具有自定义构造函数 (C++) 的类型的动态数组分配
- 删除动态数组时未定义标识符
- 在定义字符数组(井字游戏)的 for 循环中应用输入限制
- C++ 返回指向函数内定义的静态数组的指针是否有效?
- 模板类中的数组定义
- C 结构数组定义
- 在C++中为指针数组定义NULL
- 为什么局部变量不隐藏数组定义中的全局变量
- 静态数组定义错误 C++
- C++ 二维数组定义
- 这是否是 C++ 中的有效 2D 数组定义
- 模板类数组定义不是类型名称、静态或枚举器C++
- 用静态2d数组定义类的方便方法是什么(并且2d数组的大小只有在编译时才知道)
- 如何将字符数组定义为常量
- 二维数组定义
- 如何保护数组定义,防止使用非零值进行不完整的初始化
- 为3D数组定义setter/getter属性
- 在静态成员数组定义中对自身使用sizeof操作符