Re:Returning multiple values from functions in C++
by mbel on Monday March 07, 2016 @04:25AM
(#11237910)
Well, if you don't need forward declarations, you can define structs inline in function signature:
I'm not sure how portable it is though, works in gcc and in whatever ideone is using: https://ideone.com/bgZUPS
[ Parent
| on HN ]
Re:Returning multiple values from functions in C++
by gpderetta on Monday March 07, 2016 @05:09AM
(#11238037)
G++ 5.2 complains: "new types may not be defined in a return type"
An alternative in C++14:
auto hello(int c) { struct { int a; int b; } result { c, c + 1 }; return result; }
or with gcc extensions: auto hello(int c) { return (struct { int a; int b; }) { c, c + 1 }; }
Re:Returning multiple values from functions in C++
by oselhn on Monday March 07, 2016 @07:18AM
(#11238456)
I meant something like that:
struct x {int a, char* b}
x foo();
// a lot of code
struct y {char* y, int x}
y bar();
//another header
struct z {bool a, int b, char* c}
z foo2();
It is ussually the same data structure, but someone was lazy to define it properly.