Skip to content

Instantly share code, notes, and snippets.

@zed
Created November 9, 2011 23:20
Show Gist options
  • Select an option

  • Save zed/1353510 to your computer and use it in GitHub Desktop.

Select an option

Save zed/1353510 to your computer and use it in GitHub Desktop.
anonymous struct as a return type in c++11
int main()
{
int mx = [] () -> struct { int x, y ; } { return { 99, 101 } ; } ().x ;
}
$ 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