C++ 头文件中出现错误C4430
错误C4430:缺少类型说明符-假定为int。注意:C++不支持默认INT/P> 我有638个这样的错误,所以我知道这都是由一个错误引起的。我使用的这段代码在使用VS6、VS7和GCC时工作得非常好。将其迁移到VS2013时会出现一些错误。我不知道为什么它会给我这个错误。我将在它发生的地方发布一段代码。如果你需要更多的解释,请告诉我。我试着在互联网上到处寻找,但看起来C4430的出现有各种原因 许多错误中的第一个错误开始于第8行C++ 头文件中出现错误C4430,c++,warnings,C++,Warnings,错误C4430:缺少类型说明符-假定为int。注意:C++不支持默认INT/P> 我有638个这样的错误,所以我知道这都是由一个错误引起的。我使用的这段代码在使用VS6、VS7和GCC时工作得非常好。将其迁移到VS2013时会出现一些错误。我不知道为什么它会给我这个错误。我将在它发生的地方发布一段代码。如果你需要更多的解释,请告诉我。我试着在互联网上到处寻找,但看起来C4430的出现有各种原因 许多错误中的第一个错误开始于第8行 // ------------------------------
// ----------------------------------------------------------------------------
// vector-based database for fast O(1) lookups.
// ----------------------------------------------------------------------------
template< typename entity >
class VectorDatabase : public Database< entity, std::vector<entity> >
{
public:
typedef std::vector<entity> container; //This is the first of many where the error is occuring
typedef container::iterator iterator;
bool isvalid( entityid p_id )
{
return p_id < m_container.size() && p_id != 0;
}
entity& get( entityid p_id )
{
if( p_id >= m_container.size() || p_id == 0 )
throw Exception( "Out of bounds error in vector database" );
if( m_container[p_id].ID() == 0 )
throw Exception( "Invalid Item in vector database" );
return m_container[p_id];
}
entity& create( entityid p_id )
{
if( m_container.size() <= p_id )
m_container.resize( p_id + 1 );
m_container[p_id].SetID( p_id );
return m_container[p_id];
}
entityid findname( const std::string& p_name )
{
container::iterator itr = m_container.begin();
stringmatchfull matcher( p_name );
while( itr != m_container.end() )
{
if( matcher( itr->Name() ) )
return itr->ID();
++itr;
}
return 0;
}
}; // end class VectorDatabase
//----------------------------------------------------------------------------
//用于快速O(1)查找的基于向量的数据库。
// ----------------------------------------------------------------------------
模板
类向量数据库:公共数据库<实体,标准::向量>
{
公众:
typedef std::vector container;//这是许多发生错误的地方中的第一个
typedef容器::迭代器迭代器;
bool有效(entityid p_id)
{
返回p_id=m_container.size()| | p_id==0)
抛出异常(“向量数据库中的越界错误”);
if(m_容器[p_id].id()=0)
抛出异常(“向量数据库中的无效项”);
返回m_容器[p_id];
}
实体和创建(实体id p_id)
{
if(m_container.size()Name())
返回itr->ID();
++itr;
}
返回0;
}
}; // 端类向量数据库
不确定这是否造成了错误,但首先必须声明
typedef typename container::iterator iterator;
也就是说,在声明中使用额外的typename
,因为container
是一个依赖的typename,请参阅
另外,
bool中的类型entityid
是否有效(entityid p\u id)
,其余的是否定义在某个地方?如果您提供出现警告的行号,那就太好了。我编辑了这篇文章,它也作为注释出现在代码中。它从第8行开始是的,它们在某处定义。我没有收到任何显示没有定义的错误,但是C4430在所有有typedef的行上添加了我提到的额外的typename
关键字,这肯定是错误的一个原因。是的,缺少typename
是问题所在。