我在Linux编译下面的代码与gcc4.4.1基本表达式: -错误:预期之前 '<' 令牌
#include "glob.h"
#include "netlist.h"
#include "netlist_params.h"
#include "netlist_abbrev.h"
#include "lvs_util.h"
#include "lvs_report.h"
#include "lvs_data.h"
#include "compare_opts.h"
#include "flatten.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include "hash.h"
static THREAD_PRIVATE NlStringVec* ext_str_tab_v;
static THREAD_PRIVATE const char* ext_str_tab_s1;
static THREAD_PRIVATE const char* ext_str_tab_s2;
int Netlist::ExtStrHash::operator() (NlString i) const {
if (i.is_valid())
ext_str_tab_s1 = (*ext_str_tab_v)[i];
return Hash<const char*>::operator()(ext_str_tab_s1);
}
错误: -
netlist_back_1.C: In member function 'int Netlist::ExtStrHash::operator()(NlString) const':
netlist_back_1.C:24: error: expected primary-expression before '<' token
netlist_back_1.C:24: error: expected primary-expression before 'const'
netlist_back_1.C:24: error: expected ';' before 'const'
netlist_back_1.C:24: error: expected unqualified-id before '>' token
netlist_back_1.C:24: error: expected initializer before '>' token
在文件散列的散列的定义.h: -
namespace Hash {
// template <class Key> struct Hash { };
#define DECL_SIMPLE_HASH(type) \
template <> \
struct Hash<type> { \
unsigned int operator() (type x) const { return x; } \
}
DECL_SIMPLE_HASH(signed char);
DECL_SIMPLE_HASH(unsigned char);
DECL_SIMPLE_HASH(signed short);
DECL_SIMPLE_HASH(unsigned short);
DECL_SIMPLE_HASH(signed int);
DECL_SIMPLE_HASH(unsigned int);
DECL_SIMPLE_HASH(signed long);
DECL_SIMPLE_HASH(unsigned long);
DECL_SIMPLE_HASH(signed long long);
DECL_SIMPLE_HASH(unsigned long long);
#undef DECL_SIMPLE_HASH
template <>
class Hash<const char*> {
static const int M = 61; // 5;
public:
unsigned int operator() (const char* s) const {
// case insensitive, so sensitivity can be turned on/off without
// effecting hash #.
unsigned h = 0;
char c;
while (c = *s++) {
if (c >= 'A' && c <= 'Z')
c = c - 'A' + 'a';
h = M*h + c;
}
return h;
}
};
template <> struct Hash<char*> : public Hash<const char*> {};
}
编辑::我需要包括命名空间。处理他人的代码会导致愚蠢的错误。 感谢您的投票和帮助。 :)
任何帮助表示赞赏。谢谢。
写'哈希(ext_str_tab_s1)'会不会更容易? –
Hauleth
2011-12-20 20:14:04
你是否包含定义Hash是什么的东西? – tpg2114 2011-12-20 20:14:12
命名空间中是否包含和/或定义模板类'Hash'?如果是这样,可能是你的问题。 – Joe 2011-12-20 20:15:09