When should I use C++14 automatic return type deduction?

前端 未结 7 2114
南笙
南笙 2020-11-28 19:05

With GCC 4.8.0 released, we have a compiler that supports automatic return type deduction, part of C++14. With -std=c++1y, I can do this:

auto          


        
相关标签:
7条回答
  • 2020-11-28 19:37

    I want to provide an example where return type auto is perfect:

    Imagine you want to create a short alias for a long subsequent function call. With auto you don't need to take care of the original return type (maybe it will change in future) and the user can click the original function to get the real return type:

    inline auto CreateEntity() { return GetContext()->GetEntityManager()->CreateEntity(); }
    

    PS: Depends on this question.

    0 讨论(0)
提交回复
热议问题