声明和修改结构的静态阵列-CPP
Declaring and modifying Static array of structure -CPP
我在标题文件中定义了一个结构,它是这样的数组:
struct
{
int a;
char* b;
} S_element, s_array*;
static s_array my_data[3] = {1,"first", 2, "second", 3, "third" };
在源代码中,我包括这样的标题并访问此数组。我正在尝试更改数组元素结构内的字符串变量B的值,但是当我尝试更改struct Member -b的值时,程序正在崩溃。
对不起,此问题代码中的语法错误。到目前为止,我只能使用手机。
我不确定涉及静态成员的概念,并以这种方式初始化数组,而无需用于单个结构元素的卷发括号。
写作 struct{...}a;
与 struct name{...}; name a;
您不能写static s_array my_data[3]
,因为s_array
是struct,而不是类型。
另外,这不是重新启动结构数组的方法。
更改为:
typedef struct{
int a;
char* b;
} S_element, *s_array;
static S_element my_data[3] = {{1,"first"}, {2, "second"}, {3, "third"}};
看到我更改为S_Element,因为S_Array是指针,而不是结构。
另外,不要在标题中使用static
,仅在功能中。
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- #为""定义宏;静态";针对不同的上下文
- cmake如何在fedora工作站中找到boost静态库包
- OpenMP阵列性能较差
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 关于操作员新的静态阵列
- C 静态数组,例如动态阵列
- GDB打印具有虚拟函数类的非弦乐值的静态常量阵列的无效地址
- 静态函数阵列上未解决的外部符号
- C 使用谷物序列化结构的静态阵列
- 静态成员的静态阵列:初始化顺序惨败的可能性
- 声明和修改结构的静态阵列-CPP
- C 98如何在标题中初始化静态结构阵列
- C 类中的静态动态2维数阵列
- 动态和静态阵列
- 静态2D阵列初始化
- 其他静态阵列破坏了OMAPL138目标(CCS5.2)上的DSP应用程序
- 静态数组成员的尺寸返回指针的大小,而不是阵列
- C 11初始化类静态常量阵列
- 静态阵列以适应屏幕