编写一个模板函数,我声明:
template <typename T>
T invertible(T const& container, T::size_type startIndex, T::size_type endIndex);
使用 g++ 4.0.1 编译时出现错误:
error: 'T::size_type' is not a type
最佳答案
您需要添加类型名称。
即
template <typename T>
T invertible(T const& container, typename T::size_type startIndex, typename T::size_type endIndex);
在没有关于类型 T 的任何信息的情况下,编译器需要知道 T::size_type 指定了一个类型。
来自标准第 14.6.2 节:
A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword
typename
.
关于c++ - g++ "is not a type"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1301380/