How to get the data type from the template argument?

S

shuisheng

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
 
A

Andre Kostur

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;
}
 

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,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top