Connecting Tech Pros Worldwide Forums | Help | Site Map

How to get the data type from the template argument?

shuisheng
Guest
 
Posts: n/a
#1: Dec 7 '06
Dear All,

I have template classes as following

template<class T>
struct A
{
typedef T DataType;
DataType valueA;
};

template<class T>
struct B
{
T::DataType valueB;
}

When compiling, it said that T::DataType is not a type. Any method I
can get the data type from the template argument?

I appreciate your help.

Best wishes!

Shuisheng


Andre Kostur
Guest
 
Posts: n/a
#2: Dec 7 '06

re: How to get the data type from the template argument?


"shuisheng" <shuisheng75@yahoo.comwrote in
news:1165535009.790154.125100@n67g2000cwd.googlegr oups.com:
Quote:
Dear All,
>
I have template classes as following
>
template<class T>
struct A
{
typedef T DataType;
DataType valueA;
};
>
template<class T>
struct B
{
T::DataType valueB;
}
>
When compiling, it said that T::DataType is not a type. Any method I
can get the data type from the template argument?
>
I appreciate your help.
That's what's called a dependant type. Use the 'typename' keyword:

template<class T>
struct B
{
typename T::DataType valueB;
}
Closed Thread