Hi All,
How do I change the copy assignment header as shown below to allow for
different array length?
bool_vector& operator= (const bool_vector& t)
Thanks,
Hans.
template<int len>
class bool_vector {
private:
bool *v;
int i;
int sz;
public:
bool_vector() {
v=new bool[sz=len];
for (i=0; i<sz; i++) v[i]=0;
};
~bool_vector() {
delete [] v;
};
bool_vector& operator= (const bool_vector& t) {
cout << "rhs=" << sz << " lhz=" << t.sz;
if (this != &t) {
delete[] v;
v=new bool[sz]; // sz=t.sz
for (i=0;i<sz;i++) if (i<t.sz) v[i]=t.v[i]; else v[i]=0;
};
return *this;
}
};
int main()
{
bool_vector<4a,b;
bool_vector<5c;
a=b;
//c=b; // fails
}