免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1502 | 回复: 2
打印 上一主题 下一主题

[C++] 请问这里有什么问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-10-17 11:39 |只看该作者 |倒序浏览
本帖最后由 程序c 于 2012-10-17 11:41 编辑
  1. #ifndef __SYSTIME__
  2. #define __SYSTIME__

  3. #include <time.h>
  4. #include <stdint.h>
  5. #include <boost/noncopyable.hpp>


  6. class SysTime : private boost::noncopyable
  7. {

  8. public:
  9.    
  10.     explicit SysTime();
  11.     virtual ~SysTime();

  12. public:

  13.     static void set_systime(uint64_t nowtime);
  14.     static void update_systime(void);
  15.     static uint64_t get_systime(void);

  16. private:

  17.     static uint64_t m_systime = 0;
  18.    
  19. };

  20. #endif
复制代码
  1. #include "SysTime.hpp"

  2. SysTime::SysTime()
  3. {
  4. }

  5. SysTime::~SysTime()
  6. {
  7. }

  8. void SysTime::set_systime(uint64_t nowtime)
  9. {
  10.     m_systime = nowtime;
  11. }

  12. void SysTime::update_systime()
  13. {
  14.     m_systime = time(NULL);
  15. }

  16. uint64_t SysTime::get_systime()
  17. {
  18.     return m_systime;
  19. }
复制代码
我想把类的方法和类的成员都弄成静态的~
但是结果编译不过去。

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
2 [报告]
发表于 2012-10-17 11:55 |只看该作者
  1. #ifndef __SYSTIME__

  2. #define __SYSTIME__


  3. #include <time.h>

  4. #include <stdint.h>

  5. #include <boost/noncopyable.hpp>



  6. class SysTime : private boost::noncopyable

  7. {


  8. public:

  9.    
  10.     explicit SysTime();

  11.     virtual ~SysTime();


  12. public:


  13.     static void set_systime(uint64_t nowtime);

  14.     static void update_systime(void);

  15.     static uint64_t get_systime(void);


  16. private:


  17.     static uint64_t m_systime;

  18.    
  19. };


  20. #endif
复制代码
in some .cpp file:
uint64_t SysTime::m_systime=0;

论坛徽章:
0
3 [报告]
发表于 2013-06-26 14:41 |只看该作者
folklore 发表于 2012-10-17 11:55
in some .cpp file:
uint64_t SysTime::m_systime=0;


非常感谢您的回复,虽然我回的太晚了,但是谢谢您了,您的回答完全正确。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP