为什么这告诉我hash2不是模板?
Why is this telling me thehash2 is not a template?
我很困惑,为什么终端告诉我,hash2不是一个模板,当我试图编译。
我疯了吗?
template<typename Symbol>
class thehash
{
public:
size_t operator()(const Symbol & item)
{
static thehash2<string> hf;
return hf(item.getData());
}
};
template<typename string>
class thehash2<string>
{
public:
size_t operator()(const string & key)
{
size_t hashVal = 0;
for(char ch : key)
hashVal = 37 * hashVal + ch;
return hashVal;
}
};
template<typename string>
class thehash2<string>
{
这里有一个错误。你可能想写:
template<typename T>
class thehash2
{
注意,正如在注释中所说的,你不应该在模板中使用string
作为类型名。模板参数最常用的名称通常是单个字母——T
, U
,…这样它们就不会轻易与真正的类型名称混淆。
class thehash2 : public thehash<std::string>
{
(根据您的实际需要)
相关文章:
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 谁能告诉我我用 getline 做错了什么 (cpp) 格式
- 比特集告诉我的名字是什么?
- 我试图用这段代码找到二叉树的高度,但它一直返回 0,有人可以告诉我为什么吗?
- 任何人都可以告诉我我的 C++ 代码出了什么问题?
- 我可以让 valgrind 告诉我 _哪个_值未初始化吗?
- 程序告诉我,即使它们明显匹配,参数也不匹配
- 谁能告诉我为什么这段代码没有产生正确的输出?
- 谁能告诉我,程序中的错误是什么?该程序仅用于获取文件扩展名
- 为什么 gcc 告诉我我的模板不是模板?
- 代码以查找数组中的最大数字,但它仅将第一个数字显示为最大数字. 有人请告诉我为什么
- 关于这个在 Linux 上使用 gcc 编译的程序中的 vtable,nm 告诉我什么?
- 告诉我如何填充二维数组
- 我找不到瓦尔格林德告诉我的记忆链接
- 如何将char数组声明为函数参数?或告诉我此代码中还有其他问题?
- 合成错误不知道为什么会发生这种情况,请检查一下并告诉我这是我的编码还是视觉工作室
- 为什么只有一行告诉我操作员=不可行?但是其他人很好
- 有人可以告诉我波纹管代码(C++)穿了什么吗?
- 程序告诉我初始化在编写简单的C ++代码时不需要初始化的变量
- 为什么这告诉我hash2不是模板?