473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

reference in operator=

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
4 1373

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
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

ok, i fix it.
thanks

Jun 15 '07 #4
ok, i fixed it.
thanks
Jun 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: klaas | last post by:
the following code gives rise to the beneath error message, only when a matrix object is instantiated as matrix<bool>, not with matrix<float>: /*returns a reference to the object at position...
3
by: ded' | last post by:
Hello ! I've read in a magazine "reference parameter in operator= must be const, because in C++, temporary objects are const" and then my operator would not work with temporary objets. But,...
8
by: JKop | last post by:
Having decided not to use macros at all in designing my reseatable references, and having looked through the list of overloadable operators and combinations of them, I've settled on the following...
8
by: SpOiLeR | last post by:
Hello! I have a matrix class like this: class MyObject; // MyMatrix is contains MyObjects class MyMatrix { public: ...
5
by: homsan toft | last post by:
Hi, I'm (still) trying to return a pair<const Key, T> from iterator dereference. So I defined a proxy class in the obvious way: template<class KeyT, class DataT> struct ref_proxy { typedef...
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
10
by: Belebele | last post by:
Suppose that I have a method that returns references to "elements" in an iterator, and a method to advance the iterator: class Element { /* ... */ }; class Iterator { public: Element&...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
1
by: PeterAPIIT | last post by:
What is template template arguments and template typename arguments ? The reason i write in policy based design is because this is the requirement of the assignment. My code so far: ...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.