嵌套名称说明符 [英] nested-name-specifier

查看:96
本文介绍了嵌套名称说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的代码:

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抱怨语法无效:

It compiles successfully (and works) under MSVC, but gcc is complaining about invalid syntax:

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

我做错了什么?

推荐答案

此处不需要typename,因此不允许使用.

The typename is not needed there, and is therefore not allowed.

MSVC在实际使用模板之前无法正确解析模板,因此直到稍后才发现一些错误.

MSVC do not parse templates properly until they are actually used, so some errors are not found until later.

这篇关于嵌套名称说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆