std::numeric_limits::max()问题,请大虾帮忙
我有这样一个模板类:
#include <limits>
#include <list>
using namespace std;
template<typename T>
class HandleManager
{
public:
HandleManager(T);
HandleManager(T, size_t);
T provide();
void free(T);
private:
size_t maximum ;
T highest ;
std::list<T> available ;
};
/** Constructor. The default maximal value will be based on the type max.
@param init Initial handle value (use for first requested handle)
*/
template<typename T>
HandleManager<T>::HandleManager(T init)
: highest(init) //,maximum(std::numeric_limits<T>::max()) //注释掉
{
maximum = std::numeric_limits<T>::max();
}
// ============================================================================
/** Constructor
@param init Initial handle value (use for first requested handle)
@param hmax Maximal handle value
*/
template<typename T>
HandleManager<T>::HandleManager(T init, size_t hmax)
: highest(init), maximum(hmax) { }
// ----------------------------------------------------------------------------
/** Get a new handle
@return handle
@throw RTIinternalError if all handles between first and maximal are used
*/
template<typename T> T
HandleManager<T>::provide()
{
T handle = 0 ;
if (available.size() > 0) {
handle = available.front();
available.pop_front();
}
else {
if (highest < maximum)
handle = highest++ ;
}
return handle ;
}
// ----------------------------------------------------------------------------
/** Free a handle
@pre handle is a previously-provided handle
@param handle Handle to free
*/
template<typename T> void
HandleManager<T>::free(T handle)
{
if (handle + 1 == highest)
--highest ;
else
available.push_back(handle);
}
}
然后在一个类里调用 HandleManager<unsigned long> MyHandle;
但编译时出现:
warning C4003: “max”宏的实参不足
error C2589: “(” : “::”右边的非法标记
D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xmemory(156) : 编译类模板成员函数“open::HandleManager<T>::HandleManager(T)”时
with
[
T=open::Handle
]
e:\工作空间\open source\RootObject.h(77) : 参见对正在编译的类模板实例化“open::HandleManager<T>”的引用
with
[
T=open::Handle
]
错误发生在maximum = std::numeric_limits<T>::max(); 语句中,请问这是什么原因 ?