Hacker News new | ask | show | jobs
by AnimalMuppet 805 days ago
Ah, I see. Inner to the function, not inner to the class. So the C++ syntax would need to be something like:

  ClassName::functionName::innerName
Except that's not an actual C++ syntax - there isn't one.

But if you return it from a function, how do you declare the variable you assign it to? auto?

And, is auto a valid return type from a function? If not, how do you declare the function that returns this object?

1 comments

Exactly. You spell auto or an interface or base class whose derived class cannot be named. I think both are ok. In the latter case you can name the interface instead of auto.

Yes, auto is a perfectly valid return type, usually quite useful in generic code.

However, in generic code, starting at C++20, I would recommend to use concepts to name a return type that can be many different thing but that is compliant with the same "compile-time" interface.

You could do:

    forward_range auto f(auto && input);
You do not spell the return type but you are saying that type conforms to forward_range. Note that the auto type returned could be one of many unrelated types and it is computed at compile-time.