程序出现错误,尝试引用已删除的函数,是怎么回事
#include<iostream>#include<iterator>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
template<class T>
class My_ostream_iterator :public iterator<output_iterator_tag, T> {
private:
string sep; //分隔符
ostream & os;
public:
My_ostream_iterator(ostream & o, string s) :sep(s), os(o) { }
void operator ++() { }; // ++只需要有定义即可, 不需要做什么
My_ostream_iterator & operator * () { return *this; }
My_ostream_iterator & operator = (const T & val)
{
os << val << sep; return *this;
}
};
int main() {
int a[4] = { 1,2,3,4 };
My_ostream_iterator<int> oit(cout, "*");
copy(a, a + 4, oit); //输出 1*2*3*4*
return 0;
}
程序出现了错误,错误是:
C2280 “My_ostream_iterator<int> &My_ostream_iterator<int>::operator =(const My_ostream_iterator<int> &)”: 尝试引用已删除的函数 ConsoleApplication4 d:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility 458
请教各个大神这是怎么回事??