D
devphylosoff
hi
i have class array, and operator= :
I remove
.....
template <typename T2> array<T> operator= (const array<T2> rhs) {
if (this != &rhs) {
resize(rhs.size());
// a now I have 3 others ways :
/* 1 attempt */ for (iterator i=begin(); i!=end(); i++)
*i = rhs;
/* 2 attempt */ std::copy(rhs.begin(),rhs.end(), begin());
/* 3 attempt */ for (int i = 0; i < max_size(); i++)
elems = *rhs;
} return this;
}
i want copy one array to another
in loop: assert(*it1 == *it2);
then increment all elements in second array, so below assertion should
be correct:
in loop: assert(*it1 != *it2);
but is not - whatever i do on only one array in fact i do on both
-there are the same array - no matter which the above attempt I use.
I change:
array<T>& operator= (const array<T2>& rhs)
to
array<T> operator= (const array<T2> rhs)
without success.
how to do copy, not reference ?
i have class array, and operator= :
I remove
.....
template <typename T2> array<T> operator= (const array<T2> rhs) {
if (this != &rhs) {
resize(rhs.size());
// a now I have 3 others ways :
/* 1 attempt */ for (iterator i=begin(); i!=end(); i++)
*i = rhs;
/* 2 attempt */ std::copy(rhs.begin(),rhs.end(), begin());
/* 3 attempt */ for (int i = 0; i < max_size(); i++)
elems = *rhs;
} return this;
}
i want copy one array to another
in loop: assert(*it1 == *it2);
then increment all elements in second array, so below assertion should
be correct:
in loop: assert(*it1 != *it2);
but is not - whatever i do on only one array in fact i do on both
-there are the same array - no matter which the above attempt I use.
I change:
array<T>& operator= (const array<T2>& rhs)
to
array<T> operator= (const array<T2> rhs)
without success.
how to do copy, not reference ?