我一直试图在主要之前运行它(没有呼叫)。它说初始化失败了。 可能是什么原因?
编译器抱怨大括号的数量,但它们似乎没问题。
struct contain {
char* a;
int allowed;
struct suit {
struct t {
char* option;
int count;
};
struct inner {
char* option;
int count;
};
};
};
// initialize
struct contain _vector = {
.a = "John",
.allowed = 1,
.suit = {
.t = {
.option = "ON",
.count = 7
},
.inner = {
.option = "ON",
.count = 7
}
}
};
答案 0 :(得分:2)
您需要实际声明内部结构类型的成员。
struct contain {
char* a;
int allowed;
struct suit {
struct t {
char* option;
int count;
} t;
struct inner {
char* option;
int count;
} inner;
} suit;
};
答案 1 :(得分:1)
您将struct suit
声明为struct contain
中的类型,但您从未声明该类型的变量。 suit
,t
和inner
都不是变量。你可能想要像
struct suit {
struct t {
char* option;
int count;
} suit_t;
struct inner {
char* option;
int count;
} suit_inner;
} suit_object;
};
虽然t
和inner
基本上是同一时间,但您可能希望将其单独声明为类型并生成该类型的t
和inner
个变量