当前位置:首页
开发技术指南» 文章正文
    引言:

 ·怎样去循环读取文件    »显示摘要«
    摘要: f6141_dis.txt f6151_dis.txt f6161_dis.txt f6171_dis.txt f6181_dis.txt f6191_dis.txt 怎么用c去实现分别读取这些文件里的第10个字节到第20个字节之间的文本?我想用循环去实现,但不知道怎么用for循环去实现。 用f6##day##1_dis.txt(day是循环变量)去表示通用的文件名,编译通过,但运行出错 ......
    摘要: 如题! ......


std::numericlimits<T>::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();   语句中,请问这是什么原因   ?

NO.1   作者: masterz

maximum   =   (std::numeric_limits<T>::max)();   //把max用括号括起来避免和windows定义的宏混淆


 ·几个c++的问题,高手请进    »显示摘要«
    摘要: 下面的程序可以编译执行,但打印出来的数据说明构造函数和析构函数调用的次数不相等,可能是重载的<<不能用传地址/引用的方式,使得生成了局部的对象。但好象只调用了析构函数,没调用构造函数,为什么呢,有注释,请高手指点一下呀,谢谢!! 执行结果: 构造函数2创建第1个对象... 构造函数2创建第2个对象... 构造函数1创建第3个对象... td1:(3,2,1) 析构第3个对象........
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE