Return type deduction for class methods? C++1y

时光怂恿深爱的人放手 提交于 2019-12-01 17:55:18

Yes the standard should allow it according to the paper n3582. Here is an example from the paper.

Allowing non-defining function declarations with auto return type is not strictly necessary, but it is useful for coding styles that prefer to define member functions outside the class:

    struct A {
      auto f(); // forward declaration
    };
    auto A::f() { return 42; }

and if we allow it in that situation, it should be valid in other situations as well. Allowing it is also the more orthogonal choice; in general, I believe that if combining two features can work, it should work.

According to the comment by @bamboon, "Return type deduction is only supported as of gcc 4.9." so that would explain why you don't have it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!