为什么std :: numeric_limits< T> :: max()一个函数? [英] Why is std::numeric_limits<T>::max() a function?

查看:156
本文介绍了为什么std :: numeric_limits< T> :: max()一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++的标准库中,值 std :: numeric_limits< T> :: max()被指定为函数。特定类型的其他属性作为常量给出(如 std :: numeric_limits< T> :: is_signed )。所有类型为 T 的常量都作为函数给出,而所有其他常量都给定为常数值。

In the standard library of C++ the value std::numeric_limits<T>::max() is specified as a function. Further properties of a specific type are given as constants (like std::numeric_limits<T>::is_signed). All constants that are of type T are given as functions, whereas all other constants are given as, well, constant values.

这背后的理由是什么?

推荐答案

要扩展Neil的注释: std :: numeric_limit< ; T> 可用于任何数字类型,包括浮点数,如果你通过comp.lang.c ++线程,你会看到可能无法定义静态变量浮点值。

To expand on Neil remark: std::numeric_limit<T> is available for any number type including floating points number and if you dig through the comp.lang.c++ thread you'll see the mention that it might not be possible to define the static variables for floating point values.

为了一致性,他们决定将整数和浮点都放在方法之后。

So for consistency they decided to put both integral and floating points behind methods.

将改变与C ++ 0x,所以有希望。

It will change with C++0x, so there's hope.

这篇关于为什么std :: numeric_limits&lt; T&gt; :: max()一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆