我是对的,对任何浮点数的任何算术运算都是由IEEE浮点标准明确定义的吗?如果是的话,只是出于好奇,那是(+0)+(-0)什么?有没有办法在实践中用C++或其他常用的编程语言来检查这些东西?
如果两个类都是模板,为什么我不能简单地使用基类中定义的类型?是否有一些关于搜索模板成员的规则?这是我能推断出的最简单的例子:
struct iA {
using type = int;
};
template <class T> struct tA {
using type = T;
};
struct iB1 : iA {
void f(type i) {}
};
struct iB2 : tA<int> {
void f(type i) {}
};
template <class T> struct tB1 : iA {
void f(type i) {}
};
template <class T> struct tB2 : tA<int> {
void f(type i) {}
};
template <class T> struct tB3 : tA<T> {
// void f(type i) {} // …Run Code Online (Sandbox Code Playgroud) 这看起来很奇怪,但这个简单的代码使用int而不是T,并且不适用于模板T.
template <typename T>
class Polynomial {
public:
Polynomial (T i) {}
Polynomial& operator+= (const Polynomial& rhs) {
return *this;
}
};
template <typename T>
const Polynomial<T> operator+ (Polynomial<T> lhs_copy, const Polynomial<T>& rhs) {
return lhs_copy += rhs;
}
Polynomial<int> x (1), y = x + 2; // no match for 'operator+' in 'x + 2'
Run Code Online (Sandbox Code Playgroud)