1,366 questions
-4
votes
2
answers
149
views
Blackhole assignment in R [duplicate]
Suppose I have the following:
df1 <- data.frame(id=c(1,2,3))
df2 <- data.frame(id=c(2,3,4))
I want to print: (1) The number of IDs in df1 but not in df2, (2) the number of IDs in df2 but not in ...
5
votes
2
answers
161
views
Is this assignment to brace-enclosed string constant really illegal in C++?
I am porting a large codebase from Linux/g++ to MacOS/Clang. I hit this compiler error in multiple places in Clang (where g++ builds successfully and does the right thing at run time):
error: ...
-1
votes
1
answer
49
views
QSharedDataPointer for private data: how to write a good copy operator where a copy may be deleted
I had to implement a copy operator for a class which contains a QSharedDataPointer to the private data. Which is working, but only as long as I do not delete one of the copies. Other than expected it ...
3
votes
1
answer
138
views
Inherit assignment operator failure c++
Snip:
#include <optional>
template <typename>
class MyOpt;
template <typename T>
MyOpt(T) -> MyOpt<T>;
template <typename T>
class MyOpt : private std::optional<...
0
votes
3
answers
112
views
Expressions in C. Are assignments expressions despite semicolons?
I am currently learning C and in one slide the professor states that Semicolons added to an expression makes it a statement. While on the other hand it mentioned that all assignments are expressions. ...
1
vote
1
answer
97
views
C++: Inheriting the const assignment operator defined in the base class for the derived type
Many, many, many posts about inheriting operator=, with the usual answer being "it's overshadowed by the implicitly defined one, use using Base::operator= if you know what you're doing".
...
6
votes
1
answer
162
views
Overload resolution for copy assignment operator
In addition to an implicitly-defined copy assignment operator, if a class also defines an operator= without an lvalue-reference object parameter, which of the operators must be selected?
Please ...
1
vote
1
answer
76
views
Does QChar have a '=' operator?
I cannot find the definition of the = operator on its official document, neither can I find it in the source code of QChar. But I can use = without problem.
QChar c = QChar('c');
QChar d = c;
c = d;
...
2
votes
4
answers
131
views
wierd syntax with parentheses in C [duplicate]
I was given the code:
#include <stdio.h>
int main(void) {
int a = 0, b = 0, c = 0;
c = (a -= a - 5), (a = b, b + 3);
printf("a = %d, b = %d, c = %d", a, b, c); // a = 0, b =...
0
votes
0
answers
42
views
What (foo(), val) expression in C does? [duplicate]
In this snippet of C90:
extern float foo();
int bar(int a) {
int b = (foo(), a); // <- this line
return b;
}
Will foo() be evaluated?
What will happen to its return value?
3
votes
1
answer
54
views
hard-to-understand error in an augmented assignment statement in Kotlin
This is a contrived example for the sake of my understanding Kotlin language.
The class Box<T> below models a box that contains boxes of the same type T.
The question is why arr += x causes ...
0
votes
1
answer
44
views
Python variable assignment to avoid sharing the same memory space [duplicate]
I need some help eith the following code in Python, is an implementation of an ALNS heuristic for vrp that I'm trying to create.
def run_heuristic(num_customers, num_vehicles, num_iterations, ...
0
votes
0
answers
42
views
Python str = str + value is slow [duplicate]
I am writing 2 Mbyte file line by line and using string variable to populate the data line by line first
When i did in loops str = str + new_data it took couple seconds to process the script.
Once i ...
1
vote
1
answer
129
views
How to generalize a struct to an int with the assignment operator?
I'm trying to use a struct to pack multiple smaller integers into a uint32_t.
struct PackedData {
PackedData & operator=(uint32_t x) {
a = (x >> 24) & 0xFF;
b = (x &...
-1
votes
1
answer
69
views
dollar sign $ as an assignment operator for a value of string in vs code ( js ) does not work or highlighted [closed]
function sayHello (userName) {
console.log ('Hello ${userName}') ;
}
sayHello ('Mena') ;
function sayHello (userName) {
console.log ('Hello ${userName}') ;
}
sayHello ('mena') ;
// i ...
0
votes
1
answer
134
views
using memcpy for copy constructor and assignment operator for 2d array
I have 2 classes.
Pointer to an array of fixed width and Pointer to a Pointer for implementing 2d array of floats.
I wanted to understand, if and how can I use memcpy for my Copy constructor and ...
1
vote
1
answer
151
views
why does final_dictionary = starting_dictionary["c"] = 7 not assign starting_list with added key-value pair to final_dictionary
**How are these two different.
**
(1)
starting_dictionary = {
"a": 9,
"b": 8,
}
final_dictionary = {
"a": 9,
"b": 8,
"c": 7,
}
...
-1
votes
1
answer
144
views
Number raised to 2, 3, and 4 [duplicate]
I have written the following simple C++ program to output the powers of a number input by the user to indices 2, 3, and 4:
int a = 0;
cin >> a;
int a2 = a * a;
cout << "\n" &...
0
votes
0
answers
55
views
Inherit custom operator= from template base class [duplicate]
I have a template base class that implements void operator=(T value). Then I have a derived template class which should just inherit that operator, but this doesn't work. (See compile error in the ...
2
votes
1
answer
95
views
How to make operator= accept derivatives of parameter like operator+?
I don't understand why a = b doesn't print out value from operator= 5 like operator+ (which seems to allows derivatives). Why does it do this instead of allowing derivatives and how can I make it ...
0
votes
1
answer
80
views
In-place swap using tuple assigment statement
In-place swap is a technique, which is used to swap a content of two distinct variables without any temporary storage variable.
GoLang Spec mentions: A tuple assignment assigns the individual elements ...
25
votes
3
answers
3k
views
x = x*0.90; gives lossy conversion error. x*=0.90; does not. Why? [duplicate]
I have written the code:
int x = 18;
x *= 0.90;
System.out.println(x);
This code printed 16
However, when I wrote
int x = 18;
x = x * 0.90;
System.out.println(x);
it gave me the following error: ...
0
votes
0
answers
113
views
"void" Return type for overloaded operator [duplicate]
I am currently studying "Object-oriented design choices" by Dingle (2021), a required textbook for my Object-Oriented Design Class. While going through the chapter on "Move Semantics,&...
3
votes
1
answer
104
views
Differences in Assigning to Temporaries for User-Defined vs Built-in Types in C++ [duplicate]
I have been delving into the intricacies of C++ recently, and there's a specific behavior that has puzzled me: the rules and behaviors around temporaries, especially regarding taking their address and ...
0
votes
0
answers
91
views
std::optional<T> assignment operators
My reference is to options (4), (5) and (6) of std::optional::operator=
Given the premise that
The class template std::optional manages an optional contained value, i.e. a value that may or may not be ...
0
votes
1
answer
120
views
How to assign the real and imaginary parts of complex variables, individually, using the = operator in c++?
I'm trying to use the complex<> type to implement a Point class, for geometry problems.
I would like to be able to assign the value of the real and imaginary parts of the variable individually, ...
-2
votes
3
answers
104
views
Assignment operator += usage with earlier declared vs declared variable?
I am new to C and got a little confused. I have code where I am using += operator with a variable when declared but it is giving me an error for this operator, but working fine when used inversely i.e....
4
votes
1
answer
144
views
Why is assigning a container's element to the container (not) a well-defined C++?
In C++ there is the infamous problem of self-assignment: when implementing operator=(const T &other), one has to be careful of the this == &other case to not destroy this's data before copying ...
6
votes
3
answers
308
views
Copy semantics and vectors
I am dealing with objects that allocate memory for internal use. Currently, they are not copyable.
E.g.
class MyClass
{
public:
MyClass() { Store = new int; }
~MyClass() { delete Store; }
...
1
vote
1
answer
203
views
How can I construct (instead of assign) an std::array element?
I have a class that can't be re-assigned. The actual motive is that it has an std::variant member variable, and the possible types are not re-assignable, due to having some reference member variables (...
4
votes
2
answers
112
views
Why can't the compiler find the assignment operator?
template <typename T>
class MyPointer
{public:
template <typename U>
void operator=(MyPointer<U>&& other)
{
}
char* get() const { return pointer; }
...
-2
votes
2
answers
123
views
What's the difference or when should I apply ":" vs "=" in Python?
I'm new at the site but I've been looking to know the difference of the applications of ":" and "=".
I know that "=" is an assignation operator, like a= 12, so like b= ...
2
votes
1
answer
91
views
JavaScript Operator Precedence, Assignment, and Increment?
In JavaScript (JS), ++ has higher precedence than += or =. In trying to better understand operator execution order in JS, I'm hoping to see why the following code snippet results in 30 being printed?
...
0
votes
0
answers
74
views
Returning by reference during assignment overloading
The function below works with the return type Class, Class& and void. So, what's the difference between each?
//deep copies one object into another
Club& Club::operator= (Club& obj) {
...
2
votes
1
answer
155
views
How are C declarations actually parsed, based on this interesting discrepancy?
It's fairly common to see a declaration and assignment combined like this:
int beans = a * 2;
or separate, like this
int beans;
beans = a * 2;
My current understanding is that beans can be assigned ...
-3
votes
1
answer
84
views
trying to make a vector library ? But stuck in overloading of = operator
I am trying to buld the vector library . The code looks like this
#include <iostream>
#include <string>
namespace std
{
template<typename T>
class vector
{
private:
...
0
votes
1
answer
68
views
Assignment operator overloading for templated matrix class
I am implementing assignment operator function for a template matrix class.
It should take care of different datatype matrix assignments. eg Integer matrix is assigned to a double matrix.
for that i ...
2
votes
1
answer
235
views
Do constructors do the same thing as the '=' operator?
When we didn't define any = operator, how does the compiler know
to use constructors?
Isn't the constructor only called when defining a variable?
#include <string>
class Person
{
public:
...
5
votes
1
answer
176
views
Assignment operator in C
volatile int lhs = 1;
int rhs = 2;
int x = 3;
x = lhs = rhs;
Does an assigment operator return the (typeof lhs)rhs ? or Does it return new, just read value of lhs ?
It is important to me since lhs ...
1
vote
1
answer
124
views
In Java, does (a == (a = b)) produce undefined behaviour?
I'm learning Java, and I have a question about the properties of the return value of the assignment operation. I know that Java returns the value of the variable after assignment in x = y, but when ...
0
votes
1
answer
130
views
How do I assign values from a dictionary to a dataframe column in equal numbers?
I have a list of sales reps for one of 5 territories. I need to assign them to a list of leads in equal numbers.
Here's an example of the dictionary:
d = {'Large': 'Jackson', 'Large': 'Stevens', '...
13
votes
2
answers
1k
views
Why conversion function is not used for an object when it is assigned to?
I learned that we could provide conversion operators for our classes in C++. So I expected that for the following program, c=1; would've used the conversion operator int(). But to my surprise; that ...
4
votes
1
answer
1k
views
How can I define a custom assign operator overload in Kotlin?
I have a Kotlin class that wraps a mutable value.
class StringWrapper(
var value: String = ""
) {
override fun toString(): String = value
}
I use this wrapper as properties in a custom ...
-3
votes
1
answer
82
views
Why does it prints 12 instead of 10 in JavaScript [closed]
Every time I try this the console log prints 12 instead of 10:
let number1 = 3;
let number2 = 2;
number1 += number2;
number2 += number1;
let result = number1 + number2;
console.log(result);
0
votes
2
answers
127
views
Usage of '+=' in c
I don't understand why, on this code, 'b+=' return 6 instead of 5. The operation on right-end of operator '+=', should be 0.
i/2 = 4
a-4= 0
So Operator '+=' should just add: 0.
#include<stdio.h&...
1
vote
2
answers
102
views
Is the use of conversion operator forbidden for the lhs of user-defined operator= for user-defined types? If so, what part of the standars forbids it?
Take a simple class wrapping an int,
struct Foo {
int x;
} f;
and a class that holds a Foo and that can be converted to it,
struct Bar {
Foo f;
operator Foo&() {
return f;
...
0
votes
0
answers
157
views
Assignment Operator in JS: Unary or Binary?
we use an assignment operator = in order to assign a value to a variable, so the value assigned is an operand but the variable itself counts as another one?? if not is only a unary operator, that ...
3
votes
0
answers
713
views
Macbook and iMac Assignment Operator (<-) Shortcut (Option with -) Not Working in RStudio
"-" with the "option" key (refers ALT key) had been used as the assignment operator. Since RStudio became POSIT the combination of these buttons not just working in RStudio. But ...
-1
votes
1
answer
91
views
Inheriting operator= and constructor but also add an extra wrapper assignment
I have the following struct:
struct Feedback : public TaggedUnion<Feedback1Idx, String>
{
using TaggedUnion<Feedback1Idx, String>::TaggedUnion;
using TaggedUnion<Feedback1Idx, ...
1
vote
0
answers
52
views
How is it valid syntax in Java to use an assignment operator in a larger arithmetic expression?
Context: I'm mainly a Javascript/Python developer and I'm doing Java just for schoolwork.
This is the code block that perplexes me.
public static void display(int a, int b) {
a = a+b-(b=a);
System....