代码之家  ›  专栏  ›  技术社区  ›  IdeaHat

键入特征以从操作员获得提升结果

  •  1
  • IdeaHat  · 技术社区  · 12 年前

    Implicit type conversion rules in C++ operators

    列出C++的隐式类型转换。

    所以问题是,是否有一种类型特质可以做到这一点?类似的东西

    template <typename T, typename J>
    struct promotion_type
    {
      typedef decltype(operator+(const T&,const J&)) type;
    };
    

    (这不是我的问题,但它无法编译:

    /home/user/source/testdir/main.cpp:97:51: error: there are no arguments to 'operator+' that depend on a template parameter, so a declaration of 'operator+' must be available [-fpermissive]
       typedef decltype(operator+(const T&,const J&)) type;
                                                   ^
    /home/user/source/testdir/main.cpp:97:51: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
    

    )

    1 回复  |  直到 9 年前
        1
  •  3
  •   Kerrek SB    12 年前

    怎么样 decltype(std::declval<T>() + std::declval<J>()) ?