Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No. The auto there is doing some lifting so that you can declare the type afterwards. The return type is only defined once.

There is, however, a return type auto-deduction in recent standards iirc, which is especially useful for lambdas.

https://en.cppreference.com/w/cpp/language/auto.html

auto f() -> int; // OK: f returns int

auto g() { return 0.0; } // OK since C++14: g returns double

auto h(); // OK since C++14: h’s return type will be deduced when it is defined



What about

auto g() -> auto { return 0.0; }


0.0 is a double, so I would assume the return type of g is deduced to be double, if that is what you're asking.


I was more pointing out that the syntax was dumb for that particular example!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: