public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Template class help??
@ 2004-03-22  2:43 nyi nge
  2004-03-22  4:11 ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: nyi nge @ 2004-03-22  2:43 UTC (permalink / raw)
  To: gcc-help

Hi all,

I need help with template class. Say I have a template
array class with non-type argument:

template<class D, int size=10> class aType {
   public:
     D *data;
     aType(){data = new D[size]}
     ...
}

What I want to do is use it typedef. If there is no
non-type template argument 'size', just only class D,
I can use typedef aType<int> intarray; But here I
can't use typedef as int can be all integers. Is there
any way to do this? Thanks.

Nyinge

__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Template class help??
  2004-03-22  2:43 Template class help?? nyi nge
@ 2004-03-22  4:11 ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2004-03-22  4:11 UTC (permalink / raw)
  To: nyi nge, gcc-help

Hi Nyi,

Yes, there is a way to do it.

Don't use typedef.  Use another template class.  Depending on your needs, 
try one of...

template <int size=10> class intarray : public aType<int, size>
{
// yada yada yada
};

...or...

template <int size=10> class intarray
{
private:
     aType<int, size> mArray;
// yada yada yada
};

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-21 20:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-22  2:43 Template class help?? nyi nge
2004-03-22  4:11 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).