我想在以下结构中使用静态数组:
struct N{
int id;
static long history[100];
};
struct N Node[R][C]; // R is # of rows, C is # of coloumns
但是我得到了这个错误:
P.c:38:2: error: expected specifier-qualifier-list before ‘static’
static long history[100];
不知道为什么 这是否意味着我不能使用静态内部结构?
与C ++struct
允许s(就功能而言完全等同于类)不同,C ++不允许具有静态成员struct
。
C允许您具有文件作用域和函数作用域的静态变量。如果history
需要是静态的,请在访问该函数的函数中将其设为静态,如果由多个函数访问,则在文件中将其设为静态。
但是,如果您确实需要history
静态的话,那么您的struct
功能就等同于single int
,因为它static
意味着“在我所有实例之间共享一个数组struct
”。很有可能您需要使数组为非静态数组,即“每个数组struct
都有自己的数组history
”:
struct N{
int id;
long history[100];
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句