简体   繁体   中英

Template class assignment operator

I have a problem with a template class I named "DynamicArray". The only problem that I have is when I define my assignment operator. it gives me two different errors

1) the first error it gives me is

DynamicArray& says "argument list for class template "DynamicArray" is missging"

2) the second error is

DynamicArray::operator= says "template argument list must match the parameter list"

this is my program:

DynamicArray.h

#pragma once
#include <iostream>

using namespace std;

template<typename T>
class DynamicArray
{
public:
    DynamicArray();
    DynamicArray(const DynamicArray &d);
    DynamicArray& operator=(const DynamicArray &d);
    ~DynamicArray();
};

template<typename T>
DynamicArray<T>::DynamicArray()
{

}

template<typename T>
DynamicArray<T>::DynamicArray(const DynamicArray &d)
{

}

template<typename T>
DynamicArray& DynamicArray<T>::operator=(const DynamicArray &d)
{

}

template<typename T>
DynamicArray<T>::~DynamicArray()
{

}

I have looked at multiple examples and can't figure out why I have this problem.

Can anyone tell me what I am doing wrong here?

  1. Put the complete template in the header file as Neil suggested via the link to Why can templates only be implemented in the header file? .
  2. The return value from operator= should be DynamicArray<T>&

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM