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.
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.