hkB*_*sai 2 c++ templates class infinite indefinite
template <class T>
MyClass
{
public:
// ...
void MyMethod(T dbNumber)
{
// ...
T dbResult = do_some_operation_on_dbnumber(dbNumber);
if (IsInfinite(dbResult))
{
// ...
}
else if (IsIndefinite(dbResult))
{
// ...
}
else
{
// ...
}
// ...
}
static bool IsInfinite(T dbNumber)
{
// How do I implement this?
}
static bool IsIndefinite(T dbNumber)
{
// How do I implement this?
}
// ...
};
Run Code Online (Sandbox Code Playgroud)
我的代码中有一个数学运算,有时会在模板变量中返回无限且不确定的结果.我想抓住这些无限期的结果.我怎么做?
#include <limits>
using namespace std;
double d = 1.0 / 0.0;
if (d == numeric_limits<double>::infinity( ))
cout << "Its infinite, all right" << endl;
else
cout << "Not in my book" << endl;
Run Code Online (Sandbox Code Playgroud)
这有效.
| 归档时间: |
|
| 查看次数: |
9920 次 |
| 最近记录: |