Compiler can't deduce the return type?

后端 未结 3 618
夕颜
夕颜 2021-01-04 08:41

I am trying to use the decltype keyword on an auto function:

struct Thing {
   static auto foo() {
     return 12;
   }
   using type_t =
               


        
3条回答
  •  离开以前
    2021-01-04 09:30

    It's because a using inside a class or struct see the declaration but not the definition of members. So see auto but doesn't see return 12;.

    If different, would be dangerous because the definition of members can use the defined (using or typedef) types.

    Imagine something as follows

    struct Thing {
       static auto foo() {
         return type_t{};
       }
       using type_t =
           decltype(foo());
    };
    

提交回复
热议问题