T invertible(T const& container, T::size_type star...">

G ++ "not a type" error

By writing a boilerplate function, I stated:

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

Compiling with g ++ 4.0.1 I got an error:

error: 'T::size_type' is not a type
+5
source share
4 answers

As you know, T :: size_type must have a prefix with the type name. Why?

From "C ++ Templates: The Complete Guide"

A language definition solves this problem by indicating that in the general case, a dependent qualified name does not indicate a type, unless that name has a prefix with the typename keyword.

... Type name prefix for name is required if name

  • Appears in the template.
  • Is qualified
  • ,

, typename , .

+7

typename.

..

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:

, , -, , typename.

+29

T . , T:: size_type. , . , T, , , . , , - , gcc 4.0.1; -)

: -fpermissive, , , , .

+3

, , T:: size_type typename. ?

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

All Articles