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

后端 未结 5 2489
别那么骄傲
别那么骄傲 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:39

    auto diff(A const&y) const -> decltype(a-y.a) is the problem; regardless of anything else, if X and Y are different types, A and A are different types and cannot peek at each other's privates. Templates are not covariant!

    The specific error here might be an eccentricity of GCC (in that it doesn't spot that X is the same type as Y) but the more general case where you might be trying to diff two different types (and why else would you have a separate template type in your diff function?) will never work, regardless of compiler.

提交回复
热议问题