错误:C++ 中不允许使用类型名称

编程入门 行业动态 更新时间:2024-10-10 15:24:30
本文介绍了错误:C++ 中不允许使用类型名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我编译我的代码时,VC++ 返回一个错误,如上所述.受影响的行是 (brushes){5.6, 214.0 , 13.0}

When I compiled my code, VC++ returns an error, as stated above. The affected line is (brushes){5.6, 214.0 , 13.0}

更具体地说,这里是受影响的代码块

More specifically, here is the affected code block

const  brushes palette[] = {
    (brushes){5.6, 214.0 , 13.0},
    (brushes){200.0, 211.0, 12.0}
};

这段代码在 Linux 中编译得很好,那么为什么 VC++ 会发生这种情况?

This code compiles fine in Linux, so why is this happening for VC++?

画笔的定义:

typedef union {
    struct {
        double c;
        double m;
        double y;
    } t;
double v[3];
} brushes;

推荐答案

您使用的 C99 结构(第 6.5.2.5 节复合文字)不受 MS VC 支持,但 GCC 支持.

You are using a C99 construct (§6.5.2.5 Compound Literals) which is not supported by MS VC, but which is supported by GCC.

您应该能够通过删除 (brushes) 符号来编译代码:

You should be able to get the code to compile on both by dropping the (brushes) notation:

const  brushes palette[] = {
    { {   5.6, 214.0, 13.0 } },
    { { 200.0, 211.0, 12.0 } },
};

这将初始化 union 的第一个成员,即 brushes.这适用于 GCC;我相信它也应该与 MSVC 一起使用.

This will initialize the first member of the union that is brushes. This works with GCC; it should work with MSVC too, I believe.

这篇关于错误:C++ 中不允许使用类型名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 16:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中不   错误   名称   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!