【发布时间】:2014-05-04 02:53:23
【问题描述】:
标题确实说明了一切,我遇到了这个错误,我只是不知道在 & 之前放什么才能让它发挥作用?
我只使用了我认为必要的部分头文件和cpp文件
标题:
#include <iostream>
using namespace std;
#ifndef INDEXLIST_H
#define INDEXLIST_H
template <class T>
class indexList
{
public:
//constuctor, default
//Descriptions: Initializes numberOfElement to 0
// Initializes maxSize to 100
//Parameters: none
//Return: none
indexList(int size = 10);
//copy constructor
indexList(const indexList &rhs);
//destructor
~indexList();
//assignment operator
indexList &operator=(const indexList &rhs);
cpp:
//assignment operator
template <class T>
// error occurs on the line below
indexList &indexList::operator=(const indexList &rhs)
{
if(*this != rhs)
{
delete [] list;
numberOfElement = rhs.numberOfElement;
maxSize = rhs.maxSize;
list = new T[maxSize];
for(int i = 0; i < numberOfElements; i++)
{
list[i] = rhs.list[i];
}
return *this;
}
【问题讨论】:
-
哪一行显示错误?
-
cpp第三行
标签: c++ templates assignment-operator