[prog] C++ Templates

Christine Bussman olearyck at SLU.EDU
Thu Jun 26 09:05:19 EST 2003


I think the function you have labeled 'constructor' is the
real culprit here.  the normal syntax for a constructor is
classname<template thing>::classname(input)
(see comments below)you're half defining a constructor
and half defining another function named count, which
isn't a member function.  I think this is where most of the
difficulties are coming from.  Also, is '\0' necessarily an
object of class T?  this is one I really don't know about,
but I would be careful here.
Christine


what you had:
> template <typename T>
> Ordlist<T size> : count(size)
> {
>         info = new T[size * sizeof(T)];
>         for(int i=0; i<size; i++)
>                 info[i] = '\0'; // initialise array
> } // constructor
>

the first two lines in a constructor should probably be
template <typename T>
Ordlist<T>::Ordlist(int size)
{code here}

if I'm remembering correctly, the <T> is present in the
first
Ordlist because it's the name of the class, but not in the
second because it's the name of the function.


More information about the Programming mailing list