typedef with a template

X

Xavier Serrand

Hello all,

can i typedef such a déclaration ??

template <class T, int i>
struct MyStruc
{
/* some members here ...*/
};

Thanks in advance

Xavier
 
V

Victor Bazarov

Xavier said:
can i typedef such a déclaration ??

template <class T, int i>
struct MyStruc
{
/* some members here ...*/
};

typedef MyStruct<int,42> MyInt42Struct;

Beyond that, ask more particular questions.

V
 
X

Xavier Serrand

Xavier Serrand said:
Hello all,

can i typedef such a déclaration ??

template <class T, int i>
struct MyStruc
{
/* some members here ...*/
};

Thanks in advance

Xavier

Ok this seems to work

template <class T, int i>
typedef struct MyStruc
{
/* some members here ...*/
} MyStructure;

Xavier
 
S

spekyuman

Hello all,

can i typedef such a déclaration ??

template <class T, int i>
struct MyStruc
{
/* some members here ...*/

};

Thanks in advance

Xavier

You are restricted to giving the template type definition a specific
"for-instance:"

typedef MyStruc<int, 0> intPoop;
typedef MyStruc<char, 1> charPoop;
typedef MyStruc<float, 2> floatPoop;

intPoop<chicken, 123456789> henType; // Invalid
intPoop valid0; // Do these need comments? Yes, always!
charPoop valid1;
floatPoop valid2;
 
X

Xavier Serrand

"spekyuman" <[email protected]> a écrit dans le message de
Hello all,

can i typedef such a déclaration ??

template <class T, int i>
struct MyStruc
{
/* some members here ...*/

};

Thanks in advance

Xavier

You are restricted to giving the template type definition a specific
"for-instance:"

typedef MyStruc<int, 0> intPoop;
typedef MyStruc<char, 1> charPoop;
typedef MyStruc<float, 2> floatPoop;

intPoop<chicken, 123456789> henType; // Invalid
intPoop valid0; // Do these need comments? Yes, always!
charPoop valid1;
floatPoop valid2;


Thanks, Speykuman

I found a way to typedef my templated type as i wanted
Because T is defined in the class declaration, we can do :

template <typename T> class CTemplated
{
typedef struct MyStruc<T> MyStructureT;
MyStructureT m_one;
CTemplated(int n) {m_one.x = n;}
};


Xavier
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top