私のcompsciクラスでジェネリックスとテンプレートを紹介しました。任意のデータ型の格納と取得をサポートする汎用コンテナクラスを作成するように依頼されました。配列のサイズを変更する場合を除いて、すべての機能が正常に機能しています。挿入関数内でサイズ変更の呼び出しがあります。
template< typename T >
void Container< T >::insert( T magic)
{
if (index == size)
{
resize();
}
containerPtr[index] = magic;
index++;
}
サイズ変数は配列のサイズであり、インデックスは次の挿入位置です。
これが私のサイズ変更機能です:
template< typename T >
void Container< T >::resize()
{
int doubSize = size * 2;
Container< T > temp(doubSize);
for (int i = 0; i < size; i++)
{
temp[i] = containerPtr[i]; // error 1 here
}
*containerPtr = temp; // error 2 here
size = doubSize;
}
私の過負荷=
template< typename T >
const T Container< T >::operator=(const T& rhs)
{
if(this == &rhs)
{
return *this;
}
return *rhs;
}
コンパイルしようとすると、次のエラーが発生します。
1: error C2676: binary '[': 'Container<T>' does not define this operator or a conversion to a type acceptable to the predefined operator
2: error C2679: binary '=': no operator found which takes a right-hand operand of type 'Container<T>' (or there is no acceptable conversion)
ここでどこが間違っているのかわかりません...