我需要为两种类型的对象定义一个结构.两者具有完全相同的数据结构并执行相同的任务(成员方法).
唯一的区别是两种类型的数组大小不同,一种使用SIZE_A,另一种使用SIZE_B.
不需要复制结构和函数的定义.
我怎么能使用一种类型的'struct',并用不同的大小初始化它的数组?
#define SIZE_A 100
#define SIZE_B 200
typedef struct{
int matr[SIZE_A][SIZE_A]; // for another type matr[SIZE_B]
int arr[SIZE_A]; // for another type arr[SIZE_B]
int size; // will be initialized to SIZE_A or SIZE_B
int var1, var2;
}s;
void task1(s* si){
...
}
void task2(s* si){
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4254 次 |
| 最近记录: |