Questions tagged [copy-assignment]
146 questions
0
votes
1 answer
Is there a better way to assign a new value to a numpy array scalar?
I am doing some quick calculations on a scalar value from a numpy array. As it says in the documentation,
The primary advantage of using array scalars is that they preserve the
array type (Python may not have a matching scalar type available,…

Bill
- 10,323
- 10
- 62
- 85
0
votes
0 answers
Copy assignment operator deep copy on doubly linked list holding int* nodes in C++
I am trying to implement a copy assignment operator of a doubly linked list which is holding nodes of int*, but I am stuck with making a deep copy and not assigning the real pointers:
class ListOfArrays {
struct ArrayNode {
int* data_;
…

wencakisa
- 5,850
- 2
- 15
- 36
0
votes
1 answer
Why doesn't perfect forwarding (catch-all) work to implement a copy-assignment?
In a class with a series of ctors (most of which have exactly one argument), I want all one-argument ctors to also be mirrored by a corresponding assignment operator. The ctors include, but are not limited to a copy-ctor and a move-ctor. So this,…

bitmask
- 32,434
- 14
- 99
- 159
0
votes
0 answers
Copy data from one multiindex dataframe to other multiindex in pandas
I am trying to copy a multiindex dataframe to another dataframe, however, it is not working somehow. Here, is the toy example.
arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']), \
np.array(['one', 'two', 'one',…

Milan Jain
- 459
- 7
- 17
0
votes
0 answers
Arduino CPP object reference in assignment
I have the following Ardruino CPP code. This code works fine:
while (rtc.now().second() != 0) delay(50);
curDateTime = rtc.now();
I wanted to move the assignment into the loop so that I'm capturing the time I'm actually testing. I thought I could…

Gronk
- 149
- 2
- 9
0
votes
3 answers
Is this copy assignment operation safe?
#include
class HasPtr {
public:
HasPtr(const std::string &s = std::string()) :
ps(new std::string(s)), i(0) {}
HasPtr(const HasPtr &orig) :ps(new std::string(*orig.ps)), i(orig.i) {}
HasPtr &operator=(const HasPtr &rhs)…

K.Robert
- 215
- 1
- 2
- 9
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…

anddn
- 1
- 2
0
votes
3 answers
why is the copy constructor being called before copy assignment?
class LinkedList
{
public:
LinkedList() : _head(nullptr) {}
LinkedList(ListElement *newElement) : _head(newElement) {}
~LinkedList() { };
LinkedList(const LinkedList& LL);
LinkedList& operator=(LinkedList…

LotsInLife
- 13
- 1
0
votes
3 answers
Safe some memory when passing and assigning
I am new to C++ (coming from C#) and I want to get that memory stuff right from the beginning.
In the following snipped a variable of type WorldChunkCoordinates is passed by value to the inline constructor of WorldChunk and then the passed…

Noel Widmer
- 4,444
- 9
- 45
- 69
0
votes
1 answer
c++ Defining copy assignment in derived class
So I have the following simple code
#include
class Base {
public:
virtual int GetX() const = 0;
virtual int GetY() const = 0;
virtual Base& operator=(const Base&) = 0;
protected:
int x;
};
class Derived : public Base…

quetzalcoatl729
- 11
- 1
0
votes
6 answers
Copy-Assignment Operator when assigns itself
I was reading one of the recommended C++ book, on copy-assignment section it suggests;
It is cricially important for assignment operator to work correctly,
even when object is assigned to itself. A good way to do so is to copy
the right-hand…

user3858202
- 95
- 1
- 1
- 9
0
votes
2 answers
Copy constructor/Assignment operator confusion when initializing object
What's the difference between doing this:
class_name object_name = something;
and
class_name object_name(something);
From what I read here, both use the copy constructor but I don't understand why that happens and how implicit conversions come…

Veritas
- 2,150
- 3
- 16
- 40
0
votes
1 answer
Class members garbled after copy-construction or copy by assignment (sometimes)
My class NRRanNormal represents a normally-distributed random variable. By default, instances are normally distributed with mean 0 and stdev 1 (i.e., a standard normal random variable).
Sometimes when I copy NRRanNormal objects, the mean and stdev…

synaptik
- 8,971
- 16
- 71
- 98
0
votes
1 answer
Custom copy assignment operator crashes the program (C++)
I'm creating a custom class for automaticly cleaning up memory. The class contains a pointer to an SDL_Surface object and calls it's refcount when needed. The problem is when I implement the custom copy assigment operator the system crashes with the…

Mix
- 117
- 2
- 11