相关疑难解决方法(0)

什么更适合用于自动返回类型:decltype或std :: common_type <> :: type(如果可能)?

作为对我上一个问题的回答,建议尽可能使用std::common_type<X,Y>::type自动返回类型的声明而不是原始的decltype().但是,这样做我遇到了问题(使用gcc 4.7.0).请考虑以下简单代码

template<typename> class A;
template<typename X> class A {
  X a[3];
  template <typename> friend class A;
public:
  A(X a0, X a1, X a2) { a[0]=a0; a[1]=a1; a[2]=a2; }
  X operator[](int i) const { return a[i]; }
  X operator*(A const&y) const          // multiplication 0: dot product with self
  { return a[0]*y[0] + a[1]*y[1] + a[2]*y[2]; }
  template<typename Y>
  auto operator*(A<Y> const&y) const -> // multiplication 1: dot product with A<Y>
#ifdef USE_DECLTYPE
    decltype((*this)[0]*y[0])
#else …
Run Code Online (Sandbox Code Playgroud)

c++ decltype type-traits c++11

2
推荐指数
1
解决办法
487
查看次数

标签 统计

c++ ×1

c++11 ×1

decltype ×1

type-traits ×1