template 'typename' usage ..



 DEVELOP > c-Plus-Plus > template 'typename' usage ..

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER