模板推导参数类型错误
template <class TLeft, class TRight>
class CBimapEx2
{
public:
typedef typename boost::bimap<TLeft, TRight> CBimap;
typedef typename CBimap::value_type BMV_PAIR;
typedef typename CBimap::left_map::const_iterator BM_LEFT_CITER;
typedef typename CBimap::right_map::const_iterator BM_RIGHT_CITER;
public:
CBimap bmValue;
public:
unsigned int GetCount(){ return bmValue.size(); }
void InsertValue(const TLeft& left, const TRight& right){ bmValue.insert(BMV_PAIR(left, right)); }
void EraseValue(const TLeft& rValue){ bmValue.left.erase(rValue); }
void EraseValue(const TRight& rValue){ bmValue.right.erase(rValue); }
void Clear(){ return bmValue.clear(); }
bool GetValue(const TLeft& key, TRight* pValue = NULL)
{
BM_LEFT_CITER left_iter = bmValue.left.find(key);
if (left_iter != bmValue.left.end())
{
if (pValue){ *pValue = left_iter->second; }
return true;
}
return false;
}
bool GetValue(const TRight& key, TLeft* pValue = NULL)
{
BM_RIGHT_CITER right_iter = bmValue.right.find(key);
if (right_iter != bmValue.right.end())
{
if (pValue){ *pValue = right_iter->second; }
return true;
}
return false;
}
};
typedef CBimapEx2<int, std::string> CBimapID;
class Sample:public CBimapID
{
private:// This is singleton pattern trick.
Sample(){}
public:
~Sample(){};
public:
// Get the one and only global CResID
//static Sample& ResID(); //to test
static Sample& ResID()
{
static Sample obj;
return obj;
}
long GetID(std::string strID)
{
long nID = -1;
GetValue(strID, &nID);
return nID;
}
std::string GetID(long nID)
{
std::string strID;
GetValue(nID, &strID);
return strID;
}
};