Error with using decltype() in C++11 (creating opaque error message in gcc 4.7.0)

后端 未结 5 2464
别那么骄傲
别那么骄傲 2021-02-19 09:55

with the following code (a boiled-down version of my original code)

#include 
#include 

template  class A;                   


        
5条回答
  •  粉色の甜心
    2021-02-19 10:50

    There is an error with your code:

    template
      auto diff(A const&y) const -> decltype(a-y.a)
      { return a-y.a; }
    

    Here, A is a different type, so A cannot see it's a data member. Only A can see A::a.

    Edit: that said, in your particular case, X and Y are both double, so I would naively expect that to compile. Note that in the best of cases, this construction should only compile when X and Y are the same, which may not be what you want.

提交回复
热议问题