By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,377 Members | 3,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,377 IT Pros & Developers. It's quick & easy.

reference in operator=

P: n/a
hi

i have class array, and operator= :
I remove

.....
template <typename T2array<Toperator= (const array<T2rhs) {
if (this != &rhs) {
resize(rhs.size());

// a now I have 3 others ways :
/* 1 attempt */ for (iterator i=begin(); i!=end(); i++)
*i = rhs[i];

/* 2 attempt */ std::copy(rhs.begin(),rhs.end(), begin());

/* 3 attempt */ for (int i = 0; i < max_size(); i++)
elems[i] = *rhs[i];
} 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<Toperator= (const array<T2rhs)

without success.

how to do copy, not reference ?

Jun 15 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

i think this will ok

template <typename T2>
array<T2>& operator= (const array<T2rhs) {
if (this != &rhs)
{
resize(rhs.size());
for (int i = 0; i < size(); ++i)
this->[i] = rhs[i];
}
return *this;
}

it's what you need?

Jun 15 '07 #2

P: n/a
i think this will ok

i also think that, but it doesn't ok
strange.

here I have files
http://student.if.uj.edu.pl/Slawomir.Lenart/cpp/
boost_array_NEW.hpp - lines 88 - 103 - operator=
boost_array.cpp - test for my class
rest of files boost concept check or additional tools.

should I move operator= out of class, and define only
template <typename Tarray<Toperator= (const array<Trhs) ...
in fact i use array<T= array<T>, not array<T2 - but i dont know
what is relation to my problem.
>
template <typename T2>
array<T2>& operator= (const array<T2rhs) {
if (this != &rhs)
{
resize(rhs.size());
for (int i = 0; i < size(); ++i)
this->[i] = rhs[i];
}
return *this;

}

it's what you need?
no
Jun 15 '07 #3

P: n/a

ok, i fix it.
thanks

Jun 15 '07 #4

P: n/a
ok, i fixed it.
thanks
Jun 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.