Topic: question regarding templates


Author: fosterbt@sage.cc.purdue.edu (Benjamin T. Foster)
Date: Tue, 3 May 1994 04:07:54 GMT
Raw View

In the use of class and function templates, is there any way to specify that
a template, when instantiated, should take on a default *type* parameter? Ok,
here is an example of what I mean to disambiguate:

template < class T >
class vect {
  T*  base_pointer;
  int size;
  ...
public:
  vect ( int );
  ...
};

vect<T>::vect ( int maxsize )
{
  size=maxsize;
  base_pointer = new T[size];
  ...
}

then, in the declaration:
vect<int> my_vector(VECT_SIZE);

the compiler obviously instantiates the integer-type vector class.
Then here's my question: is there any way to specify a default template
argument (parameterized type), so the compiler would automatically
generate a type-class in the absence of a type-specification? Like:

vect<> vector(...); or possibly vect vector(...);???

This may be a stupid question, but please don't flame me. I have read the
book "Object Oriented Programming Using C++," written by Ira Pohl, and no-
where does he specify this "default" argument stuff. Any help would be
appreciated. Thanx in advance, etc..

Ben

"C is a very versatile language that combines the power of assembly language
 with the readability of assembly language."
    -- Someone Famous