Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1739317
  • 博文数量: 263
  • 博客积分: 1218
  • 博客等级: 少尉
  • 技术积分: 2862
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-19 02:33
文章分类

全部博文(263)

文章存档

2020年(12)

2019年(2)

2018年(10)

2016年(1)

2015年(20)

2014年(115)

2013年(46)

2012年(37)

2011年(20)

分类: C/C++

2014-06-16 22:39:41

代码比较长, 大体上是这样的:
SingletonMapClient-----类里面有一个 std::map m_mapClient, 存放的是有序对<会话句柄, 客户端信息> . 为了保证只创建一个实例才封装成类 SingletonMapClient

SingletonReceiveCmd----类里面有一个std::multimap m_multimapReceiveCmd, 存放有是有序对<会话句柄, 要请求的命令>

GrobalVarFacade ---类是在多线程序中保证互斥访问上面两个类唯一的全局变量....

LoginPack.cpp 想调用这几个类, 可是在LoginPack.cpp一一包含头文件grobal_var.h: #include "grobal_var.h"就编译不通过阿......
提示的信息就像一楼的那样????
1> c:\program files\microsoft visual studio 10.0\vc\include\limits(187) : 参见“numeric_limits”的前一个定义
1>c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(244): error C2766: 显式专用化;已定义“std::tr1::_Is_integral
1> c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(236) : 参见“_Is_integral”的前一个定义
1>c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1092): error C2766: 显式专用化;已定义“std::_Arithmetic_traits
1> c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1084) : 参见“_Arithmetic_traits”的前一个定义
1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(411): error C2766: 显式专用化;已定义“std::iterator_traits
1> c:\program files\microsoft visual studio 10.0\vc\include\xutility(404) : 参见“iterator_traits”的前一个定义

贴一下代码: grobal_var.h:
  1. #ifndef GROBAL_VAR_H_
  2. #define GROBAL_VAR_H_

  3. #ifdef WIN32
  4. #include<stdio.h>
  5. #include<map>
  6. #endif
  7. #ifdef LINUX
  8. #include<stdio.h>
  9. #include<map>
  10. #endif

  11. #include "ETIM/ETIM_Type.h"
  12. //#include "ETIM/E_P2P_API.h"
  13. #include "ETIM/E_P2P_API.h"
  14. #ifdef WIN32
  15. #include<windows.h>
  16. #endif


  17. #if defined(WIN32DLL) || defined (WIN32)
  18. #define mSecSleep(ms) Sleep(ms)
  19. typedef DWORD ETIM_threadid;
  20. #elif defined(LINUX)
  21. #define mSecSleep(ms) usleep(ms * 1000)
  22. typedef pthread_t ETIM_threadid;
  23. #endif

  24. #ifdef WIN32
  25. class Locker
  26. {
  27. public:
  28.         inline Locker() { m_hMutex=CreateMutex(NULL,FALSE,NULL); }
  29.         inline ~Locker() { CloseHandle(m_hMutex); }
  30.         inline void Lock() { WaitForSingleObject(m_hMutex, INFINITE); }
  31.         inline void Unlock() { ReleaseMutex(m_hMutex); }
  32. private:
  33.         HANDLE m_hMutex;
  34. };

  35. #endif
  36. #ifdef LINUX
  37. #endif

  38. extern Locker g_lockLock;



  39. /*class SingletonMapClient*/
  40. typedef INT32 st_ClientMapKey;
  41. typedef struct
  42. {
  43.         UCHAR ucChannel;
  44.         st_ETIM_Session SessionInfo;
  45.         UINT32 uConnectTime; //connect before ? seconds or mini seconds
  46.         CHAR bUsed;
  47. }st_ClientMapValue;
  48. typedef std::pair<st_ClientMapKey, st_ClientMapValue> PairClient;
  49. //typedef std::map<st_ClientMapKey,st_ClientMapValue> ClientValueType;

  50. class SingletonMapClient
  51. {
  52. public:
  53.         SingletonMapClient();
  54.         virtual ~SingletonMapClient();
  55.         
  56.         std::map<st_ClientMapKey,st_ClientMapValue> m_mapClient; // pair<sessionhanle, st_clientMapValue>

  57. public:
  58.         

  59.         static SingletonMapClient * GetInstance();
  60. private:
  61.         static SingletonMapClient * m_s_pInstance;
  62.         static Locker m_s_lockSingle;
  63. };


  64. /*class SingletonReceiveCmd*/
  65. typedef INT32 st_ReceiveMapKey;
  66. typedef struct
  67. {
  68.         UCHAR ucChannel;
  69.         char szFilePathName[MAX_PATH];
  70.         long lOffset;
  71.         size_t uSize;
  72.         ETIM_threadid dwThreadId;
  73.         int iSending;

  74. }st_ReciveMapValue;
  75. typedef std::pair<const st_ReceiveMapKey, st_ReciveMapValue> PairReceiveCmd; //pair<sessionHandle, ReceiveMapValue>
  76. //typedef std::multimap<st_ReceiveMapIndex, st_ReciveMapValue> RecevieCmd_ValueType;
  77. class SingletonReceiveCmd
  78. {
  79. public:
  80.         SingletonReceiveCmd();
  81.         virtual ~SingletonReceiveCmd();
  82.         std::multimap<st_ReceiveMapKey, st_ReciveMapValue> m_multimapReceiveCmd;
  83. public:
  84.         static SingletonReceiveCmd * GetInstance();
  85. private:
  86.         static SingletonReceiveCmd * m_s_pInstance;
  87.         static Locker m_s_lockSingle;

  88. };



  89. /*a Facade Pattern for all Grobal variable*/
  90. class GrobalVarFacade
  91. {
  92. //GrobalVarFacade 中的每个函数都要对互斥量加锁和解锁
  93. public:
  94.         GrobalVarFacade();
  95.         virtual ~GrobalVarFacade();
  96. public:
  97.         SingletonMapClient * GetSingeltonMapClientInstance();
  98.         SingletonReceiveCmd * GetSingletonReceiveCmdInstance();
  99.         bool AddClient(PairClient pairCli);
  100.         
  101.         bool FindClient(st_ClientMapKey cliIndex);
  102.         bool DeleteClient(st_ClientMapKey cliIndex);
  103.         UINT32 GetClientCount();

  104.         bool GetOneReceiveCmd(st_ReceiveMapKey &key ,st_ReciveMapValue &Value);

  105.         bool AddOrUpdateClient();
  106.         
  107. private:
  108.         static GrobalVarFacade *m_s_pInstance;
  109.         static Locker m_s_lockGrobalVar;

  110.         SingletonMapClient * m_p_SingletonClient;
  111.         SingletonReceiveCmd * m_p_SingetonReceiveCmd;
  112. };

  113. #endif //#ifndef GROBAL_VAR_H_
在 //LoginPack.cpp中 包含上面的头文件,就会产生错误:

  1. //LoginPack.cpp
  2. #include "ETIM/E_P2P_API.h"
  3. #include "AVSTREAM_IO_Proto.h"
  4. #include "LoginPack.h"
  5. #include "implement/grobal_var.h"
  6. //加上include "implement/grobal_var.h" 会产生这样的错误:
  7. /*1> LoginPack.cpp
  8. 1>c:\program files\microsoft visual studio 10.0\vc\include\limits(378): error C2766: 显式专用化;已定义“std::numeric_limits<char>
  9.         1> c:\program files\microsoft visual studio 10.0\vc\include\limits(187) : 参见“numeric_limits<char>”的前一个定义
  10.         1>c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(244): error C2766: 显式专用化;已定义“std::tr1::_Is_integral<CHAR>
  11.         1> c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(236) : 参见“_Is_integral<char>”的前一个定义
  12.         1>c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1092): error C2766: 显式专用化;已定义“std::_Arithmetic_traits<CHAR>
  13.         1> c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1084) : 参见“_Arithmetic_traits<char>”的前一个定义
  14.         1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(411): error C2766: 显式专用化;已定义“std::iterator_traits<std::_Bool>
  15.         1> c:\program files\microsoft visual studio 10.0\vc\include\xutility(404) : 参见“iterator_traits<char>”的前一个定义*/
  16. #include "implement/grobal_function.h"
  17. AbsLoginPack::AbsLoginPack()
  18. {
  19.      //其它实现
  20. }
我有用到iterator, 有百度了一下: 好像说是 与iterator_traits 有关,,,,,,,,是要对iterator进行重新定义吗
 通过网络查找, 说是因为没有定义 iterator_traits引起的:

 
编译环境是VS2010
事实上不像我在网络上找到的那样, 后来我将grobal_var.h头文件中所有的内容基本上都删了, 只剩下头文件还是会这样,  原来 是使用STL标准头文件出的问题.......

我在grobal_var.h中将#include删除, 所有有到grobal_var.h的.cpp文件中都这样 使用include:
#include
#include"grobal_var.h"
这样就解决了.
阅读(9218) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~