对"class"的提及含糊不清
Reference to "class" is ambigous
我想实现一个哈希表的例子。为此,我创建了一个头文件、一个hash.cpp文件和一个main.cpp文件。在我的hash.cpp中,我尝试运行一个虚拟哈希函数,它接受键值并转换为索引值。然而,每当我尝试根据该哈希类创建对象时,它就会抛出一个错误(对'hash'的引用是模糊的)。
this is my main.
#include "hash.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdio.h>
using namespace std;
int main(int argc, const char * argv[]) {
hash hash_object;
int index;
index=hash_object.hash("patrickkluivert");
cout<<"index="<<index<<endl;
return 0;
}
this is my hash.cpp:
#include "hash.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <stdio.h>
using namespace std;
int hash(string key){
int hash=0;
int index;
index=key.length();
return index;
}
this is my hash.h
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#ifndef __hashtable__hash__
#define __hashtable__hash__
class hash
{
public:
int Hash(string key);
};
#endif /* defined(__hashtable__hash__) */
您的hash
类符号与std::hash冲突
int main(int argc, const char * argv[]) {
::hash hash_object;
,但是更好的和推荐的是停止使用
污染您的全局命名空间。using namespace std;
,只在需要时使用std::cout
或std::endl
。如果你正在编写一个库,你也可以创建自己的命名空间。
此外,这里还有一些大写字母的错别字:
index = hash_object.hash("patrickkluivert");
^ I suppose you're referring to the Hash() function here
和
int Hash(std::string key) {
^ this needs to be capital as well
int hash = 0;
如果你想匹配你的声明并避免强制转换/链接错误
您的hash
类与std::hash
冲突。马上停止使用using namespace std;
。如果您想使打印语句更短,请尝试using std::cout; using std::endl;
相关文章:
- '{'标记之前的预期类名,然后在预声明时无效使用不完整的类型'class class_name'
- TypeError: [c++ addon class] 不是构造函数
- C++ "'Shape': cannot instantiate abstract class"找不到问题的根源
- 为什么我不能使用 std::unique_ptr 作为"模板<class>类"参数?
- Boost::asio::streambuf consumption() 不清空缓冲区
- 将指针传递给函数在简单的情况下有效,但在"class" -izing 之后不起作用
- 如何将 std::list of 派生类而不是 std::list of parent class 传递给函数
- 'class MyClass' 在尝试定义静态结构实例时不会命名类型
- 为什么编译器在此代码中说POW(N,K)含糊不清
- 我搞不清我的代码出了什么问题
- “距离”的提法含糊不清
- 我是不是太快了,数不清妖孽
- 对'list'的引用含糊不清
- "object.EnumConstant"而不是"Class::EnumConstant"是代码气味吗?
- 为什么不使用class关键字就无法创建对象
- 为什么这个电话含糊不清
- §9.5/8 中可能含糊不清的陈述
- 口齿不清的类
- 对"class"的提及含糊不清
- <Method> 不是<Class>