【发布时间】:2013-11-07 16:37:44
【问题描述】:
首先,这是我正在创建的矢量类,其基本功能类似于标准库矢量。我们现在正在尝试将其作为类模板。
我查看了一些人们为这个错误而苦苦挣扎的例子,但我觉得我声明我的函数的方式很好,所以我看不到问题所在。这是我的声明,
template <typename T>
class MyVector
{
public:
const MyVector& operator=(const MyVector&);
...
}
实现代码。
template <typename T>
MyVector<T>::MyVector(const MyVector& b)
{
//set the vcapacity/vsize equal to the object passed to setup for a new deep copy
vcapacity = b.vcapacity;
vsize = b.vsize;
//allocate space for a new varray that is the copy
varray = new T[vcapacity];
//copy the data into the new array
for (int i = 0; i < vsize; i++)
{
this->varray[i] = b.varray[i];
}
}
所以我基本上得到了 2 个错误,我认为它们指的是同一件事。第一个指向我在模板行之后的第一行实现,说“使用类模板需要参数列表”,第二个指向实现代码的结尾,说明“无法将函数定义与现有声明匹配”。
有什么想法吗?
【问题讨论】:
-
请同时添加实际的完整错误消息和引用的行。