Home » U++ Library support » U++ Core » Transfer Semantics - Initializer list and copy constructors
Re: Transfer Semantics - Initializer list and copy constructors [message #11884 is a reply to message #10462] |
Sun, 30 September 2007 00:27   |
 |
forlano
Messages: 1213 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
luzr wrote on Tue, 10 July 2007 22:11 | The simple rule: Do what you need. If you get crash because of broken pick semantics (the ASSERT in Vector with items = -1), use "deep copy variant" (<<= instead of =, constructor with additional int parameter (e.g. 1).
|
Hello,
for first time I needed to copy the content of a vector in another vector WITHOUT to destroy the original vector. This is my class:
class Person : Moveable<Person> {
int currentProposer;
int cursor;
public:
Index<int> preference;
int RankProposer(int k);
int GetNext(); int GetCurrentRank(); int GetCurrentProposer();
int GetProposedTo();
int FindPosition(int k);
void AcceptProposal(int k);
String ToString() const { String s; for (int i=0; i<preference.GetCount();i++) s<<AsString(preference[i]) + ' '; return s; }
Person() {currentProposer = 0; cursor = -1; }
};
Then I declared two vectors:
Vector<Person> M, R;
After some operations made with M I would like to copy M in R. I used
R<<=M;
But the program crashed. Which is the correct syntax for this task?
Thanks,
Luigi
[Updated on: Sun, 30 September 2007 00:29] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Aug 03 13:57:04 CEST 2025
Total time taken to generate the page: 0.06305 seconds
|