代码比较长, 大体上是这样的:
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:
-
#ifndef GROBAL_VAR_H_
-
#define GROBAL_VAR_H_
-
-
#ifdef WIN32
-
#include<stdio.h>
-
#include<map>
-
#endif
-
#ifdef LINUX
-
#include<stdio.h>
-
#include<map>
-
#endif
-
-
#include "ETIM/ETIM_Type.h"
-
//#include "ETIM/E_P2P_API.h"
-
#include "ETIM/E_P2P_API.h"
-
#ifdef WIN32
-
#include<windows.h>
-
#endif
-
-
-
#if defined(WIN32DLL) || defined (WIN32)
-
#define mSecSleep(ms) Sleep(ms)
-
typedef DWORD ETIM_threadid;
-
#elif defined(LINUX)
-
#define mSecSleep(ms) usleep(ms * 1000)
-
typedef pthread_t ETIM_threadid;
-
#endif
-
-
#ifdef WIN32
-
class Locker
-
{
-
public:
-
inline Locker() { m_hMutex=CreateMutex(NULL,FALSE,NULL); }
-
inline ~Locker() { CloseHandle(m_hMutex); }
-
inline void Lock() { WaitForSingleObject(m_hMutex, INFINITE); }
-
inline void Unlock() { ReleaseMutex(m_hMutex); }
-
private:
-
HANDLE m_hMutex;
-
};
-
-
#endif
-
#ifdef LINUX
-
#endif
-
-
extern Locker g_lockLock;
-
-
-
-
/*class SingletonMapClient*/
-
typedef INT32 st_ClientMapKey;
-
typedef struct
-
{
-
UCHAR ucChannel;
-
st_ETIM_Session SessionInfo;
-
UINT32 uConnectTime; //connect before ? seconds or mini seconds
-
CHAR bUsed;
-
}st_ClientMapValue;
-
typedef std::pair<st_ClientMapKey, st_ClientMapValue> PairClient;
-
//typedef std::map<st_ClientMapKey,st_ClientMapValue> ClientValueType;
-
-
class SingletonMapClient
-
{
-
public:
-
SingletonMapClient();
-
virtual ~SingletonMapClient();
-
-
std::map<st_ClientMapKey,st_ClientMapValue> m_mapClient; // pair<sessionhanle, st_clientMapValue>
-
-
public:
-
-
-
static SingletonMapClient * GetInstance();
-
private:
-
static SingletonMapClient * m_s_pInstance;
-
static Locker m_s_lockSingle;
-
};
-
-
-
/*class SingletonReceiveCmd*/
-
typedef INT32 st_ReceiveMapKey;
-
typedef struct
-
{
-
UCHAR ucChannel;
-
char szFilePathName[MAX_PATH];
-
long lOffset;
-
size_t uSize;
-
ETIM_threadid dwThreadId;
-
int iSending;
-
-
}st_ReciveMapValue;
-
typedef std::pair<const st_ReceiveMapKey, st_ReciveMapValue> PairReceiveCmd; //pair<sessionHandle, ReceiveMapValue>
-
//typedef std::multimap<st_ReceiveMapIndex, st_ReciveMapValue> RecevieCmd_ValueType;
-
class SingletonReceiveCmd
-
{
-
public:
-
SingletonReceiveCmd();
-
virtual ~SingletonReceiveCmd();
-
std::multimap<st_ReceiveMapKey, st_ReciveMapValue> m_multimapReceiveCmd;
-
public:
-
static SingletonReceiveCmd * GetInstance();
-
private:
-
static SingletonReceiveCmd * m_s_pInstance;
-
static Locker m_s_lockSingle;
-
-
};
-
-
-
-
/*a Facade Pattern for all Grobal variable*/
-
class GrobalVarFacade
-
{
-
//GrobalVarFacade 中的每个函数都要对互斥量加锁和解锁
-
public:
-
GrobalVarFacade();
-
virtual ~GrobalVarFacade();
-
public:
-
SingletonMapClient * GetSingeltonMapClientInstance();
-
SingletonReceiveCmd * GetSingletonReceiveCmdInstance();
-
bool AddClient(PairClient pairCli);
-
-
bool FindClient(st_ClientMapKey cliIndex);
-
bool DeleteClient(st_ClientMapKey cliIndex);
-
UINT32 GetClientCount();
-
-
bool GetOneReceiveCmd(st_ReceiveMapKey &key ,st_ReciveMapValue &Value);
-
-
bool AddOrUpdateClient();
-
-
private:
-
static GrobalVarFacade *m_s_pInstance;
-
static Locker m_s_lockGrobalVar;
-
-
SingletonMapClient * m_p_SingletonClient;
-
SingletonReceiveCmd * m_p_SingetonReceiveCmd;
-
};
-
-
#endif //#ifndef GROBAL_VAR_H_
在 //LoginPack.cpp中 包含上面的头文件,就会产生错误:
-
//LoginPack.cpp
-
#include "ETIM/E_P2P_API.h"
-
#include "AVSTREAM_IO_Proto.h"
-
#include "LoginPack.h"
-
#include "implement/grobal_var.h"
-
//加上include "implement/grobal_var.h" 会产生这样的错误:
-
/*1> LoginPack.cpp
-
1>c:\program files\microsoft visual studio 10.0\vc\include\limits(378): error C2766: 显式专用化;已定义“std::numeric_limits<char>”
-
1> c:\program files\microsoft visual studio 10.0\vc\include\limits(187) : 参见“numeric_limits<char>”的前一个定义
-
1>c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(244): error C2766: 显式专用化;已定义“std::tr1::_Is_integral<CHAR>”
-
1> c:\program files\microsoft visual studio 10.0\vc\include\xtr1common(236) : 参见“_Is_integral<char>”的前一个定义
-
1>c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1092): error C2766: 显式专用化;已定义“std::_Arithmetic_traits<CHAR>”
-
1> c:\program files\microsoft visual studio 10.0\vc\include\type_traits(1084) : 参见“_Arithmetic_traits<char>”的前一个定义
-
1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(411): error C2766: 显式专用化;已定义“std::iterator_traits<std::_Bool>”
-
1> c:\program files\microsoft visual studio 10.0\vc\include\xutility(404) : 参见“iterator_traits<char>”的前一个定义*/
-
#include "implement/grobal_function.h"
-
AbsLoginPack::AbsLoginPack()
-
{
-
//其它实现
-
}
我有用到iterator, 有百度了一下: 好像说是 与iterator_traits 有关,,,,,,,,是要对iterator进行重新定义吗
通过网络查找, 说是因为没有定义 iterator_traits引起的:
编译环境是VS2010
事实上不像我在网络上找到的那样, 后来我将grobal_var.h头文件中所有的内容基本上都删了, 只剩下头文件还是会这样, 原来 是使用STL标准头文件出的问题.......
我在grobal_var.h中将#include
阅读(9218) | 评论(0) | 转发(0) |