丢失的 ; 在 VC9 中编译 VC6 代码时在标识符之前
以下代码在 VC6 中编译正常,但是当我在 VS2008 中编译相同的项目时,出现以下错误 错误 C2146:语法错误:缺少 ';' 在标识符“m_pItr”之前,
template <class pKey, class Data, class pCompare,
class hKey = int, class hCompare = less<hKey>,
class sKey = int, class sCompare = less<sKey>,
class tKey = int, class tCompare = less<tKey>,
class cKey = int, class cCompare = less<cKey>>
class GCache
{
private:
typedef map<pKey, Data, pCompare> PRIMARY_MAP;
PRIMARY_MAP pMap;
PRIMARY_MAP::iterator m_pItr; //error here
//Code truncated
}
您知道这里出了什么问题吗? 具有将 C++ 代码从 VC6 迁移到 VC2005/2008 经验的人可能会提供帮助。
The following code compiles fine in VC6 but when I compile the same project in VS2008 it gives the following error
error C2146: syntax error : missing ';' before identifier 'm_pItr'
template <class pKey, class Data, class pCompare,
class hKey = int, class hCompare = less<hKey>,
class sKey = int, class sCompare = less<sKey>,
class tKey = int, class tCompare = less<tKey>,
class cKey = int, class cCompare = less<cKey>>
class GCache
{
private:
typedef map<pKey, Data, pCompare> PRIMARY_MAP;
PRIMARY_MAP pMap;
PRIMARY_MAP::iterator m_pItr; //error here
//Code truncated
}
Any ideas of what is wrong here? Someone with experience in migrating C++ code from VC6 to VC2005/2008 might be able to help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要插入“typename”,以告诉编译器 PRIMARY_MAP::iterator 在所有情况下都是一种类型。
例如
You may need to insert 'typename', to tell the compiler PRIMARY_MAP::iterator is, in all cases, a type.
e.g.
它应该是
typename PRIMARY_MAP::iterator m_pItr;
。 否则编译器认为 PRIMARY_MAP::iterator 是静态对象,并且无法将其识别为类型。 所以你必须给编译器一个提示,表明它是一种类型而不是静态对象。It should be
typename PRIMARY_MAP::iterator m_pItr;
. Otherwise compiler thinks that PRIMARY_MAP::iterator is a static object and will not be able to recognize it as a type. So you have to give an hint to the compiler indicating that it is a type and not a static object.您可能会成为常见模板问题的受害者:
应该是:
注意最后两个尖括号之间的空格。
You may be falling victim to a common template problem:
should be:
Note the space between the llast two angle brackets.