C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Return type of function available inside function

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 24 Jan 2023 17:24:31 -0500
On Tue, Jan 24, 2023 at 5:13 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Tue, Jan 24, 2023 at 9:29 PM Oleksandr Koval
> <oleksandr.koval.dev_at_[hidden]> wrote:
>
> > In:
> > auto Func2(double a, int b)
> > {
> > return_t obj; // #1
> > return a + b; // # 2
> > }
> >
> > the compiler can't know the return type at #1 because it becomes clear only at #2.
>
>
> How's that any different from the following?
>
> struct Monkey {
> int Jump(void) { return jumpiness; }
> int jumpiness;
> };

Because the language says that it is.

The member access works because all member functions defined in the
class definition are effectively placed after the end of that class
definition. Therefore, they get to access class members that were not
yet defined.

Referring to things in a function that haven't been defined yet isn't allowed.

Received on 2023-01-24 22:25:03