I met a interesting error when I tried to use copy-and-swap idiom in an abstract class. The following code is specially created to demonstrate this situation, if there is anything improper, tell me but don't focus:
template <typename T> class iter
{
public:
iter();
virtual ~iter();
iter(const iter &);
iter(iter &&) noexcept;
iter& operator=(iter);
virtual void swap(iter &);
virtual bool operator!=(const iter&);
virtual bool operator==(const iter&);
virtual bool operator++() = 0;
virtual bool operator--() = 0;
private:
T* pointer;
};
And the error message is:
iterator.h:10:18: error: cannot declare parameter to be of abstract type 'iter<T>'
iter& operator=(iter);
^
iterator.h:3:28: note: because the following virtual functions are pure within 'tier':
iterator.h:15:15: note: virtual bool iter<T>::operator++()
virtual bool operator++() = 0;
^
iterator.h:16:15: note: virtual bool iter<T>::operator--()
virtual bool operator--() = 0;
Clearly it is this line causes this error, so do I have to declare it in derived class instead of here, or there is any other advanced technique?
iter& operator=(iter);