1,364 questions
5
votes
2
answers
157
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
47
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
111
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
161
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
75
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
52
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
36
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
41
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
119
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
129
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 ...