- 论坛徽章:
- 0
|
编译文件的时候出现了以下的错误
HashTable.h: In member function ‘Element* CHashTable<Key, Element>::InsertElement(Key&, Element*)’:
HashTable.h:138: 错误:expected `;' before ‘res’
HashTable.h:139: 错误:‘res’ was not declared in this scope
......
......
HashTable.h: In member function ‘Element* CHashTable<Key, Element>::InsertEleme nt(Key&, Element*) [with Key = std::wstring, Element = CWord]’:
CDictionary.cpp:138: instantiated from here
HashTable.h:138: 错误:dependent-name ‘std::vector<Element*,std::allocator<Elem ent*> >::iterator’ is parsed as a non-type, but instantiation yields a type
HashTable.h:138: 附注:如果您想指定类型,请使用 ‘typename std::vector<Element*, std::allocator<Element*> >::iterator’
原文件代码如下:
#include <iterator>
#include <vector>
#include <algorithm>
//#include "HashFunction.h"
#if !defined(AFX_HASHTABLE_H__90D3106E_BFA1_4A9B_A165_6B6D9849F8E2__INCLUDED_)
#define AFX_HASHTABLE_H__90D3106E_BFA1_4A9B_A165_6B6D9849F8E2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
template <class Key, class Element>
class CHashTable
{
public:
CHashTable();
CHashTable(unsigned long ulBufSize);
CHashTable(unsigned long ulBufSize, unsigned long(*hashfun)(Key&, unsigned long), bool(*littlefun)( Element *, Key *));
virtual ~CHashTable();
inline Element * InsertElement(Key& key, Element * pElement); //插入关键之为key的单元的指针pElement
.....
.....
}
template<class Key, class Element>
inline Element * CHashTable<Key, Element>::InsertElement(Key& key, Element * pElement)
{ //插入关键值为key的单元的指针pElement
unsigned long temp = HashFunction(key, m_ulBufSize);
std::vector<Element *>::iterator res;
res=std::lower_bound(m_pData[temp].begin(), m_pData[temp].end(), &key, IsLittle);
if( res == m_pData[temp].end())
{
m_pData[temp].push_back(pElement); m_ulEleCnt++;
}
else if( !IsEqual(*res, &key)) {
m_pData[temp].insert(res, pElement); m_ulEleCnt++;
}
else return *res;//如果键值已经存在则直接返回该单元的指针
return 0; //如果键值不存在则插入该单元,并返回0
} |
|