Questions tagged [copy-assignment]
146 questions
1
vote
1 answer
Inherited addition assignment op., how do I return the proper type?
I have this class to factorize common operations on N-dimensional vector spaces:
template
struct BaseVector
{
float m_data[N];
// Common operations like dot product, magnitude, test for unity, etc.
};
Note: I really want to…

Julien-L
- 5,267
- 3
- 34
- 51
0
votes
0 answers
In a chaining call, is copy assignment called?
I would like to understand when a copy constructor or assignment is called. Assume the following:
class Foo {
public:
Foo()
{
cout << "foo constructor " << this << endl;
test_ = 44;
}
Foo(const Foo& f)
{
cout <<…

Sam
- 1
- 1
0
votes
0 answers
Confusion on template copy assignment function
[First of First: Vs2019 on Windows10, only C++11 supported]
I've got confused on template copy assignment function like:
enter image description here
I found the specilization version is not working, why it is not equal to copy assignment function?…

Louis
- 1
- 1
0
votes
0 answers
How to prevent setorder function from reordering another data.table?
data.table setorder function also changes the ordering of another data.table.
library(data.table)
DT_setorder = data.table(name = c("aaaa", "bb", "ccc"), n_character = c(4,2,3))
DT_setorder_ORIGINAL = DT_setorder
#Sort DT_setorder by n_character in…

oguz
- 1
- 1
0
votes
0 answers
Using copy assignment operator with linked list
the main.cpp has list4 = list3 = list1 which test the overloaded operator
all the lists have 3 doubles but list 4 has an additional double appended later to it giving it 4 doubles.
I have to display all 3 lists but when displaying them the double…

nobody00shader
- 1
- 2
0
votes
0 answers
arrays not assignable but if member within struct it works
Why does assignment work if I use an array as a struct member but is not permitted if used in isolation?
struct Foo{
int arr[2]{100, 1000};
};
int main(){
Foo a{};
Foo b{2, 20};
a = b;
// works
int da[2];
int…

CD86
- 979
- 10
- 27
0
votes
0 answers
Use cases of a copy assignment operator that returns const
I have seen code that defines a copy assignment operator to return a const reference, e.g.
const MyClass & operator= (const MyClass &);
I'm confused about the intention, and how such operator can be used.
For example, let's say I use it to do…

Amelio Vazquez-Reina
- 91,494
- 132
- 359
- 564
0
votes
1 answer
Is there a better way to copy a matrix in Julia than copy()?
I just realized that the "=" operator in Julia acts more like a pointer for matrices than an assignment. For example, if I have a matrix A and I set a new matrix B with B=A, then any modification to B will also apply to A. Instead, I want to…

Ron Snow
- 13
- 4
0
votes
0 answers
why changes applied to new df created by slicing like df[['x','y']] creates changes in the original df?
df[['High','Symbol']]=df[['High','Symbol']].replace("ethusd", "ETHUSD")
since df[['High', 'Symbol']] creates a new Dataframe why are the changes are being made to the original Dataframe?
it's like-
new_df = original_df["High", "Symbol"]
new_df =…

Shubham Bhardwaj
- 7
- 2
0
votes
0 answers
C++ Copy assignment with same object
In the well-known C++ Primer book I found the following code snippet
Message& Message::operator=(const Message &rhs)
{
// handle self-assignment by removing pointer before inserting them
remove_from_Folders(); // updating existing Folders
…

J.Doe
- 19
- 1
- 2
0
votes
2 answers
How to implement copyable and movable wrapper around reference counted type?
Suppose a C API provides an opaque struct with internal reference counting:
struct Opaque {
int data;
int refcount;
};
struct Opaque* opaque_new(int data) {
return new Opaque {
.data = data,
.refcount = 1
};
}
int…

Niklas
- 3,753
- 4
- 21
- 29
0
votes
0 answers
AUTOSAR C++ Rule 6-2-1 - Move and Copy Assignment Operators
The following code violates AUTOSAR C++ rule 6-2-1: Move and copy assignment operators shall either move or respectively copy base classes and data members of a class, without any side effects. Move assignment performs actions other than moving…

KplnMoon
- 151
- 1
- 10
0
votes
0 answers
Copy assignment operator for class with dependent pointer
I’m doing an exercise in which I’m supposed to implement a copy-assignment operator for a class that looks as follows:
class Foo : public SuperFoo {
Bar* fBar1;
Bar* fBar2;
~Foo() {delete fBar1; delete fBar2;}
// members without…

user202542
- 211
- 1
- 8
0
votes
0 answers
Am I Incorrectly Writing my Copy Assignment Operators?
I've been working on a personal project where I code a simple Blackjack game, nothing too fancy. However, in an attempt to make copy assignment operators for my Card class, my CLion linter is suggesting that how I am writing them is incorrect and is…
0
votes
0 answers
define or delete copy ctor in a helper class/struct that uses neither?
I have the following helper utility class defined in a header:
Util.h
struct Timer
{
std::chrono::time_point< std::chrono::steady_clock > start { std::chrono::steady_clock::now( ) };
std::chrono::time_point< std::chrono::steady_clock >…

digito_evo
- 3,216
- 2
- 14
- 42