Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > typedef with a template

Reply
Thread Tools

typedef with a template

 
 
Xavier Serrand
Guest
Posts: n/a
 
      07-10-2007
Hello all,

can i typedef such a déclaration ??

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

Thanks in advance

Xavier


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-10-2007
Xavier Serrand wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Xavier Serrand
Guest
Posts: n/a
 
      07-10-2007

"Xavier Serrand" <(E-Mail Removed)> a écrit dans le message de
news:4693ce6b$0$5069$(E-Mail Removed)...
> 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


 
Reply With Quote
 
spekyuman
Guest
Posts: n/a
 
      07-10-2007
On Jul 10, 2:21 pm, "Xavier Serrand" <(E-Mail Removed)> wrote:
> 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;

 
Reply With Quote
 
Xavier Serrand
Guest
Posts: n/a
 
      07-10-2007

"Xavier Serrand" <(E-Mail Removed)> a écrit dans le message de
news:4693d24a$0$5106$(E-Mail Removed)...
>
> "Xavier Serrand" <(E-Mail Removed)> a écrit dans le message de
> news:4693ce6b$0$5069$(E-Mail Removed)...
> > 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 NOT to work
>
> template <class T, int i>
> typedef struct MyStruc
> {
> /* some members here ...*/
> } MyStructure;
>
> Xavier
>
>



 
Reply With Quote
 
Xavier Serrand
Guest
Posts: n/a
 
      07-10-2007

"spekyuman" <(E-Mail Removed)> a écrit dans le message de
news:(E-Mail Removed) ups.com...
On Jul 10, 2:21 pm, "Xavier Serrand" <(E-Mail Removed)> wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
typedef of template<T> x to member x in template class squarewave@blockhead.net C++ 1 02-20-2009 08:15 PM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Extracting template types from a typedef'd template declaration Adam Nielsen C++ 3 10-19-2007 09:54 AM
Typedef of a template? Richard van Wegen C++ 3 07-15-2003 07:22 AM
template typedef as return type Robert A. T. Kaldy C++ 1 07-09-2003 06:25 PM



Advertisments