在g ++中,我可以这样做:
struct s
{
int a, b;
};
void MyFunction(s) { }
int main()
{
MyFunction((s) { 0, 0 });
return 0;
}
但在Visual Studio中,它不起作用。是否有任何方法可以使它工作或一些替代语法,而无需创建变量并初始化它(并且没有向结构添加构造函数,因为它将使其非聚合,并且它将无法在聚合中初始化)?< / p>
答案 0 :(得分:0)
我的C有点生疏,但除非你struct s
,否则你不必使用typedef
吗?像这样:
struct s
{
int a, b;
};
void MyFunction(struct s) { }
int main()
{
MyFunction((struct s) { 0, 0 });
return 0;
}
或
typedef struct s
{
int a, b;
} s_t;
void MyFunction(s_t) { }
int main()
{
MyFunction((s_t) { 0, 0 });
return 0;
}