typename liability for inherited typedefs

L

Levent

Please consider the following Parent and Child template classes:

template <class T>
class Parent {
public:
typedef T type;
typedef T& ref;
/* pack of typedefs */
};

template<class T>
class Child: public Parent<T>
type data;
public:
ref get() {return data;}
};

(gcc) warning: `Child<T>::type' is implicitly a typename
implicit typename is deprecated
(same for ref)

which emphasizes the use and importance of `typename' keyword and is
great, unlike MS compiler.... And thus I guess, above code is not
acceptable according to the standards...

But, where does the typename supposed to appear for derived typedefs
(without listing them all over again in Child)?
 
K

Kai-Uwe Bux

Levent said:
Please consider the following Parent and Child template classes:

template <class T>
class Parent {
public:
typedef T type;
typedef T& ref;
/* pack of typedefs */
};

template<class T>
class Child: public Parent<T>

insert:

{
typedef typename Parent<T>::type type;
typedef typename Parent said:
type data;
public:
ref get() {return data;}
};

[snip]


Best

Kai-Uwe Bux
 
L

Larry I Smith

Levent said:
Please consider the following Parent and Child template classes:

template <class T>
class Parent {
public:
typedef T type;
typedef T& ref;
/* pack of typedefs */
};

template<class T>
class Child: public Parent<T>
type data;
public:
ref get() {return data;}
};

(gcc) warning: `Child<T>::type' is implicitly a typename
implicit typename is deprecated
(same for ref)

which emphasizes the use and importance of `typename' keyword and is
great, unlike MS compiler.... And thus I guess, above code is not
acceptable according to the standards...

But, where does the typename supposed to appear for derived typedefs
(without listing them all over again in Child)?

template <class T>
class Parent {
public:
typedef T type;
typedef T& ref;
/* pack of typedefs */
};

template<class T>
class Child: public Parent<T> {
typename Parent<T>::type data;
public:
typename Parent<T>::ref get() {return data;}
};

Regards,
Larry
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top