Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

函数返回匿名结构体无法编译 #36

Open
MrSoul8715 opened this issue Oct 18, 2024 · 2 comments
Open

函数返回匿名结构体无法编译 #36

MrSoul8715 opened this issue Oct 18, 2024 · 2 comments

Comments

@MrSoul8715
Copy link

小彭老师好,《现代C++入门:RAII内存管理》一课中提到的:初始化列表妙用,解决函数多返回值,更加fancy的写法无法编译通过。
示例代码:
struct {
    bool b1;
    double d1;
} test_anoy() {
    return {false, 1.0};
}
编译错误:
test.cpp:9:1: error: new types may not be defined in a return type
9 | struct {
| ^~~~~~
test.cpp:9:1: note: (perhaps a semicolon is missing after the definition of ‘’)

@archibate
Copy link
Collaborator

对不起!是msvc特定写法,不是标准的写法

@MrSoul8715
Copy link
Author

谢谢小彭老师!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants