| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"ma740988" |
| Date: |
07 Sep 2006 08:28:40 PM |
| Object: |
template 'typename' usage .. |
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.
.
|
|
| User: "Victor Bazarov" |
|
| Title: Re: template 'typename' usage .. |
07 Sep 2006 08:45:32 PM |
|
|
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<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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
|
|
|
|

|
Related Articles |
|
|