Topic: Help: Templates!


Author: mmediko@hubcap.clemson.edu (Medikonda Muralidhar)
Date: 10 Apr 1994 07:12:37 GMT
Raw View
Hello!
 I am kind of new to C++ and am unable to compile the following
template class set up! I looked in ARM and Lippman Book and also referred
to FAQ but with little luck.. Please let me know if I am missing
something or ......

Thank you all very much!!

(1) ****************************

I declared a template class:
 template <class T, int size>
 class X   {
 public :
  X();
  ....
  ...
 };

and I am unable to create an instantiation of the class.
for example if I declare: X x<int, 75>;

I got the following error ... ARM and Lippman book didnt help much! I also
looked in FAQ hoping to find some answer to these questions!!

"./X.H", line 59: error:  template argument for formal: size is not
a suitable constant.


(2) ****************************
  For the above class i declared a prototype of outstream operator
in the following way:
template <class T, int size>
 ostream &operator<<(ostream&, X<T,size>);

 Once again, it wouldnt compile giving me the following error!!

/X.H", line 16: error:  function template parameter size must be a type





Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Tue, 12 Apr 1994 21:23:59 GMT
Raw View
In <2o88t5$qq8@hubcap.clemson.edu> mmediko@hubcap.clemson.edu (Medikonda Muralidhar) writes:


>Hello!
> I am kind of new to C++ and am unable to compile the following
>template class set up! I looked in ARM and Lippman Book and also referred
>to FAQ but with little luck.. Please let me know if I am missing
>something or ......

>(1) ****************************

>I declared a template class:
> template <class T, int size>
> class X   {
> public :
>  X();
>  ....
>  ...
> };

>and I am unable to create an instantiation of the class.
>for example if I declare: X x<int, 75>;

>I got the following error ... ARM and Lippman book didnt help much! I also
>looked in FAQ hoping to find some answer to these questions!!

>"./X.H", line 59: error:  template argument for formal: size is not
>a suitable constant.

 Look right to me.

>(2) ****************************
>  For the above class i declared a prototype of outstream operator
>in the following way:
>template <class T, int size>
> ostream &operator<<(ostream&, X<T,size>);

> Once again, it wouldnt compile giving me the following error!!

>/X.H", line 16: error:  function template parameter size must be a type

 Function templates can only take class types.
--
 - Paul J. Lucas
   AT&T Bell Laboratories
   Naperville, IL