Template weirdness
1 messages in this thread
I'm playing with templates in Symantec C++ and I have come across somthing that
I
can't understand. The following is an abridged version of some
code that comes from a C++ book. The program won't compile if
the template function's parameter is constant. It will compile
if it is not constant.
I an error stating that WriteAll1 is already defined. I get
other errors such as ';' expected, undefined identifier 'a' and
a warning, value of expression not used. If I remove the 'const',
it all goes away.
I can't see anything syntactically wrong with the version with the
const parameter. Any ideas?
// Ed
// Display vector contents
template<class T>
void WriteAll1(const Vector<T> &a)
{
int i;
cout << "Vector contents (" << a.GetNElem() << " items):\n";
for (i = a.GetMin(); i <= a.GetMax(); ++i)
cout
<< " vector["
<< setfill(' ')
<< setw(2)
<< setiosflags(ios::showpos)
<< i
<< resetiosflags(ios::showpos)
<< "] == "
<< a[i]
<< endl;
}
void SomeFunction()
{
Vector<float> dVector(low, high);
// do something …
WriteAll1(dVector);
Vector<float> copy(dVector);
// do some more stuff …
WriteAll1(copy);
}