4

Can anyone help me understand why I am getting the following error?

'vcr’ is not a template

Here is the template class declaration:

#include <iostream>
#include <complex>

using namespace std;

template<class T>
class vcr<complex <T> >
{
  int length;
  complex<T>* vr;
public:
  vcr(int, const complex<T>* const);
  vcr(int =0, complex<T> =0);
  vcr(const vcr&);
  ~vcr() {delete[] vr;}
  int size() const{ return length;}
  complex<T>& operator[](int i) const { return vr[i];}
  vcr& operator+=(const vcr&);
  T maxnorm() const;
  template<class S>
  friend complex<S> dot(const vcr<complex<S> >&, const vcr<complex<S> >&);
};
greatwolf
  • 20,287
  • 13
  • 71
  • 105
Stephen Jacob
  • 889
  • 1
  • 15
  • 33

1 Answers1

3
template<class T> class vcr<complex <T> >{

... is a partial template specialization. There is a missing general variant, which would (at least) look like this, and which must be visible at the point of the partial specialization:

template<class T> class vcr;

You do not need to provide a body for the general form.

Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
  • Ok, so basically without the general variant, a partial specialization cannot be done. I don't know how a very good c++ book that I have could miss out on that point. Thanks a ton!! – Stephen Jacob Jul 27 '13 at 07:43
  • @StephenJacob: May I ask which book? With names like Sutter, Vandevoorde, Josuttis, Meyers, Alexandrescu, you can't make too much wrong in any case. – Sebastian Mach Jul 29 '13 at 13:49
  • C++ and Object-Oriented Numeric Computing for Scientists and Engineers- Daoqi Yang, its an older edition, probably it could be that I didn't read it thoroughly. Thanks again for your help. – Stephen Jacob Jul 29 '13 at 17:12
  • @StephenJacob: From the age of the book, it looks too old to me, unfortunately. My honest advice is a newer book which covers at least C++2003, or better, C++2011. :) – Sebastian Mach Jul 29 '13 at 21:04
  • Thank you for your time, I'll seriously take that into consideration. – Stephen Jacob Jul 30 '13 at 11:25
  • @StephenJacob: Welcome, it is not easy to find good books and resources for C++. Stackoverflow has a good resource. Search for "the definitive C++ books" (I don't remember the exact title, but that search should show you) :) – Sebastian Mach Jul 31 '13 at 05:18
  • @StephenJacob: By accident just found it: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list?rq=1 , and again, you're welcome :) – Sebastian Mach Aug 06 '13 at 21:01