Created
November 9, 2011 23:20
-
-
Save zed/1353510 to your computer and use it in GitHub Desktop.
anonymous struct as a return type in c++11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main() | |
| { | |
| int mx = [] () -> struct { int x, y ; } { return { 99, 101 } ; } ().x ; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ g++ -std=c++0x anonymous-struct.cc | |
| anonymous-struct.cc: In function ‘int main()’: | |
| anonymous-struct.cc:3:43: error: expected ‘;’ after struct definition | |
| anonymous-struct.cc: In lambda function: | |
| anonymous-struct.cc:3:43: error: expected ‘{’ before ‘;’ token | |
| anonymous-struct.cc: In function ‘int main()’: | |
| anonymous-struct.cc:3:43: error: invalid conversion from ‘main()::<lambda()>::<anonymous struct> (*)()’ to ‘int’ [-fpermissive] | |
| anonymous-struct.cc:3:64: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘int’ in return | |
| anonymous-struct.cc:3:71: error: expected primary-expression before ‘)’ token | |
| $ g++ --version | |
| g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 | |
| Copyright (C) 2011 Free Software Foundation, Inc. | |
| This is free software; see the source for copying conditions. There is NO | |
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment