Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

0 votes
1 answer
61 views

How to Implement operator-> for a Custom UniquePtr Class in C++? [duplicate]

I am trying to write my own implementation of unique_ptr in C++, and here is my UniquePtr header file: #include <iostream> template <typename T> class UniquePtr { T* ptr; public: ...
user25687822's user avatar
0 votes
1 answer
39 views

Remove boilerplate code when writing operator overloads

When I made my vector3 struct I noticed the operator functions were almost identical to eachother vector3 vector3::operator+(float scalar) const { return vector3(x + scalar, y + scalar, z + ...
enies lobby's user avatar
2 votes
1 answer
121 views

What does `operator () { ... }` do in Dart?

Here is a simple dart class: class MyOperatorClass { int operator () { return 5; } } I noticed today that this compiles without any issues. This led me to wonder, what does operator ()...
Taylor Brown's user avatar
1 vote
1 answer
85 views

operator<< for enum class just doesn't work

I have the following code: logging.hxx #include <iostream> #include <string> #include <sstream> #include "singleton.hxx" #include "utils.hxx" class FGaugeLogger:...
TheEagle's user avatar
  • 5,914
-1 votes
1 answer
233 views

How to overload the subscript operator in C++? [duplicate]

I'm working on a C++ project and I need to implement subscript operator overloading for a class. Specifically, I want to be able to use the square bracket notation ([]) on an object of my class to ...
Avacado78329's user avatar
-3 votes
1 answer
81 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: ...
satej dhakane's user avatar
0 votes
1 answer
41 views

Cannot implement a custom operator via pattern matching

Basically, I need a function that accepts two lists and attempts to return a 2-list containing the head elements of both the input lists. Couple of corner cases: if both input lists are empty, the ...
coderodde's user avatar
  • 929
0 votes
1 answer
102 views

How can time.Duration use operators in Go?

from my understanding operators are only defined for builtin types and can't be defined for user types so: a := 1 b := 2 c := a + b // possible but as soon as you define your own types you need to do:...
Fractale's user avatar
  • 1,514
0 votes
0 answers
176 views

<=> operator overloading compare two vectors

I am attempting to implement overloading for the <=> operator for my Vector class. I have defined the operator in the header file (.h), but when I try to implement it in the source file (.cpp), ...
DanielG's user avatar
  • 277
0 votes
2 answers
304 views

Are operators in C implemented as functions like C++?

I was reading a tutorial on operator overloading in C++ when I saw this: In C++, operators are implemented as functions. By using function overloading on the operator functions, you can define your ...
user21290559's user avatar
-2 votes
3 answers
297 views

How does this overloading of square brackets work [duplicate]

I want to avoid printing space (" ") or an underscore ("_") after the last element of an array while printing them using a for loop. The problem mentions one of the way to do so, I ...
Faizan Ahmed's user avatar
0 votes
0 answers
31 views

The operator+ overloading unwanted side effect [duplicate]

Tried to overload operator+ but looks like there is an unwanted side effect, it modifies one of the arguments. How am I supposed to do it? #include <iostream> #include <string> #include &...
KcFnMi's user avatar
  • 6,019
1 vote
5 answers
243 views

In C#, How can I create or overload an assignment operator to possibly assign two values at once?

This is probably a stupid question, but just in case.... We have a 3rd party package with weird models like: public partial class CountingDevice { public int countingDeviceNo { get; set; } ...
Brian Kessler's user avatar
2 votes
2 answers
243 views

Best way to use += (add and assign) and -= (subtract and assign) operators on generic type without having to check for type

My application uses objects of type Tag<T> where the Tag property Value is of type T. The application interprets a custom script language into C#. I can assign Tag Value after the interpretation ...
theguyguy's user avatar
2 votes
2 answers
222 views

Why does C++ let you overload the * and -> operators separately?

Given that the * operator returns a reference to the object, and since -> is basically a shorthand for (*a).b, why does C++ define a separate overload? To me it seems like you would want to keep * ...
k huang's user avatar
  • 413

15 30 50 per page
1
2 3 4 5
28