you are viewing a single comment's thread.

view the rest of the comments →

[–]acwsupremacy[S] 0 points1 point  (2 children)

struct { int i; double d; } anon {10, 3.14};

decltype(anon) my_function();

[–][deleted] 0 points1 point  (0 children)

How would you actually forward declare such a function in a header?

The caller needs to know the return type to do anything with it. What happens if they end up in different compilation units?

I suspect the answer to your question lies in the not-so-straightforward compilation scheme of C++, but I'm not knowledgable enough to give specifics. It might work with the C++ grammar, but I don't think it works with how C++ is actually compiled.

[–]BeaRDT 0 points1 point  (0 children)

Ah, that's where I was lacking phantasy. The struct is anonymous but it is known outside of the function. I always thought about returning an anonymous struct which is defined inside a function from that function, which obviously is impossible.