模板类:错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
Template Class: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我在代码中遇到了此错误:
- 错误
- C2143:语法错误:在"<"之前缺少";"
- 请参阅对正在编译的类模板实例化"哈希表"的引用
- 错误 C4430:缺少类型说明符 - 假定为 int。注意:C++不支持默认整数
- 错误 C2238:在";"之前出现意外令牌
在私有函数的这一行中发现错误:
vector<HashEntry> array;
#ifndef _HASHTABLE_H
#define _HASHTABLE_H
#include <vector>
enum EntryType { ACTIVE, EMPTY, DELETED };
Template <class HashedObj>
struct HashEntry
{
HashedObj element;
EntryType info;
HashEntry( const HashedObj & e = HashedObj( ), EntryType i = EMPTY )
: element( e ), info( i ) { }
};
template <class HashedObj>
class HashTable
{
private:
vector<HashEntry> array;
int currentSize;
const HashedObj ITEM_NOT_FOUND;
bool isActive( int currentPos ) const;
int findPos( const HashedObj & x ) const;
public:
explicit HashTable( const HashedObj & notFound, int size = 101 );
HashTable( const HashTable & rhs )
: ITEM_NOT_FOUND( rhs.ITEM_NOT_FOUND ),
array( rhs.array ), currentSize( rhs.currentSize ) { }
const HashedObj & find( const HashedObj & x ) const;
void makeEmpty( );
void insert( const HashedObj & x );
void remove( const HashedObj & x );
const HashTable & operator=( const HashTable & rhs );
};
#endif
如何修复此错误 C4430?
HashEntry
本身就是一个模板类,不会自动从包含的类中推断出模板参数类型HashTable
。您需要更改array
声明,如下所示
template <class HashedObj>
class HashTable {
private:
std::vector<HashEntry<HashedObj>> array;
// ^^^^^^^^^^^
// ...
};
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 缺少类型说明符 - 假定为 int.注意 c++ 不支持 default-int
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- 错误C4430:丢失类型指定词 - 假设INT.注意:C 不支持对我的构造函数的默认设置
- CREATESTRUCT错误C4430:缺少类型说明符-假定为int.注意:C++不支持默认的int C:xdc
- 错误 1 错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 模板类:错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 错误 C4430、C2146 - 缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- srand(time(NULL)):错误 C4430:缺少类型说明符 - 假定为 int.注意:C++不支持默认整数
- 这是什么意思?:注意:参数 1 没有从"int"到"const 帐户"的已知转换
- VC++缺少类型说明符-假定为int.注意:C++不支持default-int
- C2143 缺少 '*' 之前的';' 和 C 4430 缺少类型说明符 - 假定为 int。注意 C++ 不支持 default-int
- 错误c4430缺少类型说明符-假定为int.注意:c++不支持default-int生成器