丢失的 ; 在 VC9 中编译 VC6 代码时在标识符之前

发布于 2024-07-23 10:27:39 字数 688 浏览 3 评论 0原文

以下代码在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江湖正好 2024-07-30 10:27:39

您可能需要插入“typename”,以告诉编译器 PRIMARY_MAP::iterator 在所有情况下都是一种类型。

例如

class  GCache
{
    private:

        typedef map<pKey, Data, pCompare> PRIMARY_MAP;
        PRIMARY_MAP pMap;

        typename PRIMARY_MAP::iterator m_pItr;

//Code truncated
}

You may need to insert 'typename', to tell the compiler PRIMARY_MAP::iterator is, in all cases, a type.

e.g.

class  GCache
{
    private:

        typedef map<pKey, Data, pCompare> PRIMARY_MAP;
        PRIMARY_MAP pMap;

        typename PRIMARY_MAP::iterator m_pItr;

//Code truncated
}
少女净妖师 2024-07-30 10:27:39

它应该是 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.

暖心男生 2024-07-30 10:27:39

您可能会成为常见模板问题的受害者:

class cKey = int, class cCompare = less<cKey>>

应该是:

class cKey = int, class cCompare = less<cKey> >

注意最后两个尖括号之间的空格。

You may be falling victim to a common template problem:

class cKey = int, class cCompare = less<cKey>>

should be:

class cKey = int, class cCompare = less<cKey> >

Note the space between the llast two angle brackets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文