匿名结构作为返回类型 [英] Anonymous struct as a return type

查看:63
本文介绍了匿名结构作为返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码 使用 vc++ 19.00.23506 编译正常(标志:/Wall/WX/Za) 和 vc++ 19.10.25109.0 (flags: /Wall/WX/Za/permissive-, 这可以检查在 http://webcompiler.cloudapp.net),但是 不能用 clang 3.8.0g++ 6.3.0 编译(标志:-std=c++11 -Wall -Wextra -Werror -pedantic-errors).它是 vc++ 中的错误吗?标准是否禁止这种结构?

The following code compiles fine with vc++ 19.00.23506 (flags: /Wall /WX /Za) and with vc++ 19.10.25109.0 (flags: /Wall /WX /Za /permissive-, this can be checked at http://webcompiler.cloudapp.net), but doesn't compile with clang 3.8.0 and g++ 6.3.0 (flags: -std=c++11 -Wall -Wextra -Werror -pedantic-errors). Is it a bug in vc++ and does the standard prohibit such constructions?

struct
{
}
foo()
{
    return {};
}

int main()
{
}

推荐答案

MSVC 出现错误:

[dcl.fct]/9 不应在返回或参数类型中定义类型...

[dcl.fct]/9 Types shall not be defined in return or parameter types...

这篇关于匿名结构作为返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆