2,706 questions
-4
votes
1
answer
174
views
Why am I getting "nan" when I try to overload the modulo operator in C++? [closed]
I am trying to overload the % operator in C++ to make it do division instead of modulo. For example, 5 % 4 should give me 1.25 after overloading.
But I get "nan". Why?
This is the code I ...
1
vote
1
answer
162
views
Redefining new and delete operators
I want to redefine new and delete operators to use a custom allocator in a c++ project with multiple translation units. Here are the redefines written in the memops.hpp file:
#pragma once
#include &...
0
votes
1
answer
165
views
conditionally enable conversion operator with SFINAE
[Note: I'm stuck with C++17.]
I have a class template that is instantiated over a fairly large number of types (~25). A few of them can correctly be converted among one another, and I would like to ...
3
votes
2
answers
197
views
Lifetime of temporary objects used while chaining overloaded member access operator->
According to what I know, the result value of an overloaded operator->() can be any type T provided that T is either a pointer type or it is a class/struct which also exposes an overloaded operator-...
3
votes
2
answers
142
views
Calling member arrow operator -> recursively
The member arrow operator is treated by the compiler in a special way. Since an overloaded arrow operator can have an arbitrary return type, several such operators from different classes may need to ...
2
votes
3
answers
177
views
C++ How to define the spaceship operator for a template class?
Im trying to define the spaceship operator for a simple template string class.
namespace mylib
{
template <size_t N>
struct String
{
String()
{
*data = '\...
7
votes
1
answer
175
views
Wrong computation of sum in a constant expression
My program after porting to Visual Studio shows some weird results. After reduction I came to this minimal reproducible example:
consteval auto operator +( auto x, auto&& y ) {
return x += ...
0
votes
1
answer
98
views
Is it possible to invoke a different version of an overloaded class operator based on whether the call is made from inside or outside the class?
I am developing quite a large Class whose objects require relatively costly validation if they are created by the public constructors, but for which the validation can be dispensed with for private ...
2
votes
0
answers
88
views
Silo compilation error: no match for ‘operator<<’
Compile Silo and get the following error
error: no match for ‘operator<<’ (operand types are ‘std::ostringstream’ {aka ‘std::__cxx11::basic_ostringstream<char>’} and ‘std::pair<const ...
0
votes
0
answers
85
views
C++ operator== doesn't work but an actual function does [duplicate]
I got a function:
bool equal(int var, std::initializer_list<int> list)
{
return std::find(list.begin(), list.end(), var) != list.end();
}
which works, I got no error when I use the function....
-1
votes
1
answer
143
views
Precedence of pre-increment operation over post-increment operation [duplicate]
package test;
public class Test {
public static void main(String [] args) {
int a = 10;
int b = 12;
System.out.println( ++a == 11 || b++ == 12);
...
3
votes
2
answers
128
views
Class conversion operator is not called implicitly
In the program below, class A has a convert-to-int operator. Class B has a convert-to-A operator. While the compiler converts A to int implicitly, it fails to do so for converting B to A:
class A
{
...
-1
votes
1
answer
235
views
Cython : How can we properly call add, sub, mul & divide operator?
In .pxd file, I wrote
_Point operator+(const _Point other) const
_Point operator -(const _Point other) const
bool operator==(const _Point other) const
In .pyx file, I wrote
def __eq__(...
4
votes
1
answer
229
views
Can I mark a function with noexcept if it has an argument passed by copy?
So I wanted to improve the noexcept of some operators and functions in my code
can I mark this function noexcept ?
std::string remove_suffix(/*passed by copy*/ std::string s)
/*noexcept*/
// is ...
1
vote
1
answer
60
views
Python operate 'in' on tuple won't match by whole word [duplicate]
It seems the operator 'in' on tuple won't only match the whole string if there is only one item in the tuple. The behavior is different from 'list' and 'set'.
I don't understand where the difference ...
-10
votes
1
answer
83
views
Operator Precedence in JS between ? and || [closed]
In the image above, I get the value some new value as the output. Could somebody explain me why that is happening? I thought I would get test value as the output but it doesn't seems to be the case. ...
1
vote
1
answer
150
views
How does the operator "Pointwise Logical Not"(.!) work in Swift?
I learn Swift and use Swift operators (https://developer.apple.com/documentation/swift/operator-declarations) and saw the operator "Pointwise Logical Not"(.!). I started Googling and came ...
0
votes
0
answers
23
views
"no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'Diem2D')"
enter image description here
i tried to used operator istream and ostream but it doesn't work. I'm writing a HinhTron class from the existing Diem2D class to use point coordinates from the 2D class. ...
0
votes
0
answers
50
views
can I override c++ operator[] with only one function? [duplicate]
I have a code that works like this:
template<size_t size>
struct myClass {
public:
std::array<uint8_t, size> bytes;
bool operator==(const myClass<size>& o) const {
...
1
vote
1
answer
318
views
PowerShell collection operators -in and -contain not acting as expected
I have a calculated PowerShell variable that may be set to $True (Boolean), or 'True' (String), or $False (Boolean), or 'False' (String), and I want to test if it's "True" (Boolean or string)...
0
votes
1
answer
965
views
Get an Array from HashSet in c# with operator [..]
Are these range operator and indexer? I have never seen them used like this [..h].
Line 6 in this code:
public static void Main(string[] args)
{
int[] a ={1,2,3,4,5,6,7,8,9};
HashSet<int>...
-2
votes
1
answer
68
views
Segmentation fault when I'm trying to overload operator<< for char
When I'm trying to overload operator<< for char and use it which std::cout something is wrong.During compilation I don't have any errors but when i type ./a.outi see Segmentation fault (core ...
2
votes
2
answers
123
views
c++ compilation failure of ambiguity related to implicit conversion
Try to compile the following code.
#include <string>
#include <boost/any.hpp>
class V
{
public:
V& operator=(int i)
{
v = i;
return *this;
}
V& operator=(...
0
votes
2
answers
167
views
When testing my code, using cout for my class operator results in an operator error
I am receiving this error:
main.cpp: In function ‘int main()’:
main.cpp:14:36: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘void’)
14 | std::cout << ...
-1
votes
1
answer
63
views
Implementing ||= (object,object) operator for older browsers
Android WebView have trouble with emscripten generated code. When trying to load page, it complains = is unexpected in ||= string. ||= is logical OR operator with assignment. I am locking for ...
0
votes
1
answer
53
views
Operator overload = not copying to 2nd variable-object
Trying to just copy one object array to a second array minus first item in array (which I don't believe should matter). (First array 33 items and 2nd array has 32). Nothing is copying over. 2nd array ...
0
votes
0
answers
164
views
C# implicit operator for class with generic type to other generic type
I got a C# class with a generic type. I'd like to have an implicit operator which converts an instance of this class to an instance of the same class with another generic type parameter.
class MyClass&...
0
votes
0
answers
94
views
c++ Posterior Decrement Operator Overloading Value Passing Problems
I'm using vs2022 and I'm confused about the c++ post-decrement operator overloading value passing, why does overloading a function that returns a value instead of a reference also affect the object ...
4
votes
2
answers
118
views
Why my C code is slowed down if I am using += operator
Edit
I remove some part of the question because it might be confusing > and thanks of answers I should be able to found out by myself.
I am trying to write a program that resample a signal using a ...
2
votes
1
answer
101
views
c++ calling operator()() in derived class not working
I have a abstract base class having operator()(), operator and virtual operator()(...) methods. In derived class i am overriding the virtual method but i cannot call the opearator()() method. And i ...
-1
votes
2
answers
148
views
java and Arithmetic Operators and Increment [duplicate]
It is one of the simple operations and I do not understand why and I just save it, but this bothers me, so I want to understand why?
int a = 2;
int b = 4;
int c = 10;
a = b++;
System.out.println(a);
a ...
1
vote
1
answer
111
views
Mendix Java ERROR: operator does not exist: bigint = character varying Hint: No operator matches the given name and argument types
After upgrading to v9 in Mendix, one of our Java actions is causing an error.
The error can be seen below:
ERROR: operator does not exist: bigint = character varying
Hint: No operator matches the ...
2
votes
1
answer
36
views
Generic type BoundedComponent struct
I want to do a struct for boundedElements like number that has a max and min value. However I'm stuck on how to do this.
Here is an example of a property. The setfield method is just a method to set a ...
0
votes
1
answer
187
views
Orion-ld fails to establish a connection with the MongoDB Community Operator due to a connection string issue
I am attempting to connect Orion-LD to the MongoDB Community Operator in a Kubernetes (k8s) environment, but I am encountering the following error:
time=Friday 06 Oct 15:25:17 2023.339Z | lvl=WARN | ...
0
votes
1
answer
74
views
Why won't my bool variable change its value
So, i'm having a hard time with this code i wrote. The way it should be working is switching the bool is_on variable between True and False, and while is_on is True, it keeps printing some text. ...
0
votes
1
answer
35
views
Error in angle_model$edd : $ operator not defined for this S4 class
This seem to be a recurrent error message but solutions seem to be rather case specific for what I'm seeing (I'm starting with R so every step is difficult for me still). I'm following the script for ...
0
votes
0
answers
73
views
(a>b)||(a<b) - or logical operator - what does it do?
I'm struggling to understand what the following command is checking.
(a>b)||(a<b)
I have defined a as 8 and b as 3. The returning result is TRUE.
Is this checking whether
a>b is true; or
a ...
0
votes
1
answer
215
views
Airflow 2.5.3 - invalid source format 'parquet' is not valid value
I'm migrating to Composer version 2.4.1 and AIrflow 2.5.3. Some DAGS that I use the BigQueryCreateExternalTableOperator are returning an error when creating the external table, I am passing the file ...
-4
votes
2
answers
213
views
Making integer caculator using operator overloading but not work [closed]
I'm making integer calculator using C++.
Why is the following not working?
#include <iostream>
#include <string>
using namespace std;
class Number {
int i;
public:
Number(int i) ...
0
votes
1
answer
139
views
Option Strict On prohibits operands of type Object for operator '&' in vb.net
I have an error in the code below if I make the strict option to ON but if I make it OFF then the error does not appear. How can I use without error with the strict option being on?
Thanks
Dim Invno ...
1
vote
0
answers
67
views
ostream operator<< resolution fails when used from different namespaces
I made overload for ostream operator<< for std::vector in namespace printable.
As far as I understand, ADL will not see this overload implicitly, because std::vector is not a member of printable,...
2
votes
5
answers
4k
views
Unpack / pack operator
I'm looking to find various ways that a packing / unpacking operator is implemented. As an example:
*[1,2,3] --> 1,2,3 (one array scalar value unpacked to three values)
*1,2,3 --> [1,...
0
votes
1
answer
546
views
Bitnami Grafana-operator persistence problem
I am trying to deploy bitnami/grafana-operator to AKS with persistence. I want to be able to create Dashboards in UI and they to be persistent. I am using Helm chart, where the persistence.enabled is ...
0
votes
3
answers
176
views
using typeof operator in string interpolation to check data type of variable when running the code output is not coming correct
let num = 1
let st = 'data'
console.log(typeof `${num}`, typeof `${st}`)
the output of the first variable should be number but it's printing string when I am using string interpolation console....
0
votes
0
answers
60
views
Can operator overloading solve the compiler error when calling a function with pointers to a vector of vectors in C++?
#include <string.h>
#include <vector>
#include <iomanip>
using namespace std;
void JoinRows(double *C, double *A, int nrows, int ncols, double *B, int mcols);
// Function to join ...
0
votes
1
answer
180
views
Airflow operator to run multiple Big Query Job
I'm trying to run an IF ELSE statement in Airflow that involves delete and insert of dataset based on the what is the current month.
I have tried to use BigQueryInsertJobOperator but it doesn't allow ...
0
votes
0
answers
90
views
I have a question about C Operator Precedence and Associativity. Newbie. Help me [duplicate]
I am a newbie to C programming. Now, I am trying to understand the topic "C Operator Precedence and Associativity". Especially, I would like to pay attention to the order of evaluation with ...
0
votes
1
answer
46
views
How to make an addition with types byte and short
I saw in previous questions that it is impossible to make a direct addition without a cast but...
How do you explain that this following tip works?
byte startValue = 2;
byte addingValue1 = 7;
byte ...
-1
votes
1
answer
974
views
In javascript, is "0" falsy or truthy? [duplicate]
In JS, it's not clear if '0' is truthy or falsy.
So, we have :
Boolean('0') == true, because it's a non-empty string.
But: ('0' == false)
The brain-itching starts from here :
(!'0' == false)
And then ...
0
votes
1
answer
42
views
why does java cant figure out data type of "result2" without type casting it as it figure out datatype of "result1"? [duplicate]
int result1 = 10;
result1 -= 5.5;// due to compound assignment this will not cause error and result will be 4
System.out.println(result1);
int result2 = 10;
result2 = (int) (result - ...