g ++“不是类型”错误 [英] g++ "is not a type" error

查看:109
本文介绍了g ++“不是类型”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写模板函数,我声明:

Writing a templated function, I declared:

template <typename T>
T invertible(T const& container, T::size_type startIndex, T::size_type endIndex);

使用g ++ 4.0.1编译我遇到错误:

Compiling with g++ 4.0.1 I got the error:

error: 'T::size_type' is not a type


推荐答案

当你发现T :: size_type需要以typename为前缀。
为什么?

As you found out T::size_type needs to be prefixed with typename. Why?

C ++模板:完整指南


语言定义解决了这个问题,通常指定一个依赖限定名称​​不

...当名称时,名称的名称前缀是必需 p>

... The typename prefix to a name is required when the name


  1. 显示在范本中

  2. 符合资格

  3. 不是用作基类规范列表或在引入构造函数定义的成员初始化列表中

  4. 依赖于模板参数

  1. Appears in a template
  2. Is qualified
  3. Is not used as a list of base class specifications or in a list of member initializations introducing a constructor definition
  4. Is dependent on a template parameter

此外,除非至少前三个条件成立,否则不允许使用类型名前缀

Furthermore the typename prefix is not allowed unless at least the first three previous conditions hold.

这篇关于g ++“不是类型”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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