By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,564 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,564 IT Pros & Developers. It's quick & easy.

template 'typename' usage ..

P: n/a
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<Tvalue_type;
};

template <class Dummy, class traits>
class compound {
public:
typedef std::vector<typename traits::value_typevalue_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.

Sep 8 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ma740988 wrote:
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<Tvalue_type;
};

template <class Dummy, class traits>
class compound {
public:
typedef std::vector<typename traits::value_typevalue_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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 8 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.