Questions tagged [move-assignment-operator]
55 questions
0
votes
0 answers
What does the author mean by "leave the object in an assignable state"?
The following is a snippet right at the end of this article by Mr. Thomas Becker:
X& X::operator=(X&& rhs)
{
// Perform a cleanup that takes care of at least those parts of the
// destructor that have side effects. Be sure to leave the object
…
![](../../users/profiles/411165.webp)
Ayrosa
- 3,089
- 1
- 14
- 28
0
votes
2 answers
Creating a move assignment function, keep getting "pointer being freed was not allocated"
I am trying to create a move assignment function but I keep get getting "pointer being freed was not allocated"
const MyString& MyString::operator=(MyString&& move){
cout<< "Move Assignment" << endl;
if(this != &move){
delete[] str;
…
![](../../users/profiles/10157262.webp)
Dhruv Patel
- 25
- 5
0
votes
1 answer
Commenting out `move constructor` and `move assignment operator` makes compilation error
I grabbed the following code from Ten C++11 Features Every C++ Developer Should Use. I want to see the output with / without move constructor and move assignment operator. The original code compiles well. But if I comment out implementation of the…
![](../../users/profiles/2589553.webp)
duong_dajgja
- 3,878
- 1
- 28
- 53
0
votes
0 answers
Fixing assignment of an object's pointer members via smart pointers
I am learning more about smart pointers in C++14.
Consider the following MWC:
#include
#include
#include
class House {
public:
House &operator=(const House &house) = default;
House(const House &house) = default;
…
![](../../users/profiles/2072863.webp)
Eduardo
- 619
- 5
- 23
0
votes
2 answers
How to take advantage of the Move Semantics for a better performance in C++11?
After many trials I still do not understand how to properly take advantage of the move semantics in order to not copy the result of the operation and just use the pointer, or std::move, to "exchange" the data pointed to. This will be very usefull to…
![](../../users/profiles/2315094.webp)
user2315094
- 509
- 8
- 23
0
votes
1 answer
C++ rule of five for class that has dynamic memory
So I'm writing the big five for a class that has dynamic int array
struct intSet {
int *data;
int size;
int capacity;
intSet();
~intSet();
intSet(const intSet& is);
intSet(intSet &&is);
intSet &operator=(const intSet& is);
intSet…
![](../../users/profiles/6516145.webp)
anddn
- 1
- 1
0
votes
1 answer
When move constructor will get called in C++11?
I am not able to understand why why move constructor is not getting called while move assignment is able to while if I use move function in Line X , it used to call the move constructor . Can anybody tell what will be the way or syntax to call the…
![](../../users/profiles/3798283.webp)
user3798283
- 457
- 3
- 9
-1
votes
1 answer
How to correctly transfer the ownership of a shared_ptr?
I have the following code snipet:
// code snipet one:
#include
#include
#include
struct A {
uint32_t val0 = 0xff;
~A() {
std::cout << "item gets freed" << std::endl;
}
};
typedef…
![](../../users/profiles/4028358.webp)
Dongwei Wang
- 425
- 5
- 13
-1
votes
2 answers
c++ copy assignment and move assignment are not being called
I am trying to implement copy and move assignments, but I don't understand how should I use them. I have read the following topic
When did copy assignment operator called?
But it did not work for me.
Class:
class Directory{
string…
![](../../users/profiles/7681051.webp)
Alex Lavriv
- 311
- 1
- 10
-1
votes
1 answer
Move assignment operator, move constructor
I've been trying to nail down the rule of 5, but most of the information online is vastly over-complicated, and the example codes differ.
Even my textbook doesn't cover this topic very well.
On move semantics:
Templates, rvalues and lvalues aside,…
![](../../users/profiles/5171360.webp)
bigcodeszzer
- 854
- 6
- 20