加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 嵌套名称说明符

发布时间:2020-12-16 05:47:05 所属栏目:百科 来源:网络整理
导读:我有一个代码如: namespace mymap { template class Key,template typename T class Allocator myownmap { typedef pairconst unsigned int,Key typename _myPair; typedef multimapunsigned int,Key,lessKey,Allocator_myPair typename _entriesType; }}
我有一个代码如:
namespace mymap {
    template <class Key,template <typename T > class Allocator> myownmap {
        typedef pair<const unsigned int,Key> typename _myPair;
        typedef multimap<unsigned int,Key,less<Key>,Allocator<_myPair> > typename _entriesType;
    }
}

它在MSVC下成功(并且工作)编译,但gcc正在抱怨无效语法:

.hpp:20: error: expected nested-name-specifier before ‘_myPair’
.hpp:20: error: two or more data types in declaration of ‘_myPair’

我在做错什么?

解决方法

不需要类型名称,因此不允许.

MSVC不要正确解析模板,直到它们被实际使用,所以一直没有找到错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读