模板专用化:不是模板

Template specialization: Is not a Template

本文关键字:专用      更新时间:2023-10-16

有人能帮我理解为什么会出现以下错误吗?

"vcr"不是模板

以下是模板类声明:

#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> >&);
};
template<class T> class vcr<complex <T> >{

是部分模板专用化。有一个缺失的通用变体,它(至少)看起来是这样的,并且必须在部分专业化时可见:

template<class T> class vcr;

您不需要为通用表单提供正文。