我需要定义一个具有预定值的常数数组。 这些值是我定义为struct的整数对。 我怎样才能做到这一点?
我已经尝试了很多次,但是我找不到一种使它作为常量工作的方法。我遵循了以下说明:How to create an array of const structs,但仍然无法正常工作。
初始尝试:
typedef struct Pair {
int min;
int max;
} pair;
//
typedef pair typePaid[N];
#define typePaid[N] = {(min = 15, max = 30), (min = 15, max = 30), (min = 15, max = 45), (min = 30, max = 60)};
最新尝试:
typedef struct Pair {
int min;
int max;
} pair;
const pair typePaid[N] = {{pair.min = 15, pair.max = 30},...};
最新错误:
error: expected primary-expression before ‘.’ token
const pair typePaid[N] = {{pair.min = 15, pair.max = 30}, {pair.min = 15, pair.max = 30}, {pair.min = 15, pair.max = 45}, {pair.min = 30, pair.max = 60}};
// It's the same for every .min or .max statement
Compilation failed.