template 'typename' usage ..

M

ma740988

I'm wading my way through Josuttis template text. I'm having a hard
time understanding some things. So given:

template <class T>
class generic_traits {
public:
typedef T value_type;
};
template <class T>
class vector_traits {
public:
typedef std::vector<T> value_type;
};

template <class Dummy, class traits>
class compound {
public:
typedef std::vector<typename traits::value_type> value_type;
};
template < typename Dummy, typename T >
void run_it ( typename compound< Dummy, T >::value_type&);

Why is it necessary for me to qualify the arguments to the method
'run_it' with 'typename'?
Why not:
void run_it ( compound< Dummy, T >::value_type&);

Futhermore given:

template < typename T >
struct types {
typedef std::complex < T > complex_type;
typedef std::vector < complex_type > cvec_type;
typedef std::vector < T > vec_type;

typedef typename vec_type::size_type vsize_type; //$$$
typedef typename cvec_type::size_type cvsize_type; // $$$
};

Is it safe to state that the use of 'typename' pertaining to the lines
marked "$$$" is necessary because vec_type and cvec_type is an
unqualified type? I'm trying to get my head around in understanding
why the compiler is unaware those entities are types.
 
V

Victor Bazarov

ma740988 said:
I'm wading my way through Josuttis template text. I'm having a hard
time understanding some things. So given:

template <class T>
class generic_traits {
public:
typedef T value_type;
};
template <class T>
class vector_traits {
public:
typedef std::vector<T> value_type;
};

template <class Dummy, class traits>
class compound {
public:
typedef std::vector<typename traits::value_type> value_type;
};
template < typename Dummy, typename T >
void run_it ( typename compound< Dummy, T >::value_type&);

Why is it necessary for me to qualify the arguments to the method
'run_it' with 'typename'?

This is covered in the FAQ. Please take a habit of reading the FAQ
before posting.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top