template <class ElementType,int Dimension=1>
class Vector : public vector<ElementType> {
public:
Vector & operator+= (const Vector & a){
cout << " a " << a << endl;
transform (this->begin(), this->end(), a.begin(), this->begin(), plus<ElementType>());
return *this;
};
friend ostream & operator<< (ostream & stream, Vector t) {
stream << "(";
copy (t.begin(), t.end()-1, ostream_iterator<ElementType>(stream,","));
return stream << *(t.end()-1) << ")";
};
};
1)在运行时我收到错误消息:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
我发现这条消息是由cout << " a " << a << endl;
2) 如果该cout << .....
操作未成功完成,但会添加一些垃圾this
而不是 a 的内容。
有什么建议么?