テンプレートのコピーコンストラクターについて
Posted: 2017年5月06日(土) 22:40
以下のコードを書いたところ、コピーコンストラクターにエラーメッセージが表示されてしまいます。エラーメッセージを見ても、どこが間違っているのか全く見当がつかないので、ご指摘お願いします。
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class T>
class DynArray {
T* pData;
int size;
public:
DynArray() {
pData = NULL;
size = 0;
}
DynArray(const DynAarray& theOther) { //ここにエラーメッセージが表示されてしまう。
size = 0;
pData = NULL;
*this = theOther;
}
~DynArray() {}
void InsertAt(const T& newElement, int position);
void RemoveAt(int position);
const DynArray<T>& operator=(const DynArray<T>& theOther);
};
template<class T>
const DynArray<T>& DynArray<T>::operator=(const DynArray<T>& theOther) {
if (this != &theOther)
delete[] pData;
size = theOther.size;
if (size == 0) { pData = NULL, return *this; }
pData = new T[size];
for (int i = 0; i < size; i++)
pData[i] = theOther.pData[i];
return *this;
}