gpt4 book ai didi

c - 我收到此错误 "conversion to non scalar type requested"

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:02 24 4
gpt4 key购买 nike

您好,我正在创建一个这样的示例程序

#include<stdio.h>
int main()
{
typedef struct {
int a;
int b;
}v;
v m;
int g =54;
m=(v)g;

}

编译时出现错误,因为请求转换为非标量类型。这里有什么问题。

最佳答案

vint 大小不同,编译器没有关于如何从 int 转换为 v< 的规则.

编译器有标量类型(char、short、int、long、float、double)之间的转换规则。

如果要给struct赋值,要么需要同类型的struct,要么单独给字段赋值:

m.a = 54;
m.b = 32;

关于c - 我收到此错误 "conversion to non scalar type requested",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23496244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com