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)
)
最佳答案
decltype(std::declval<T>() + std::declval<J>())
怎么样? ?
关于c++ - 键入特征以从运算符(operator)处获取提升结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22849906/