operator-overloading Questions

3

Solved

I have 2 classes which represent a matrix: 1. RegularMatrix - O(n^2) representation 2. SparseMatrix - a matrix that is represented as linked list (without zeros). lets say i have: RegularMatrix a...

0

I'm looking at possible designs for a custom stream class. Half an hour of searching on- and off-site have not led to an answer to my queries, so I'm asking a new question instead. Take std::endl a...
Bratton asked 31/5, 2021 at 17:44

6

Solved

I am writing a small matrix library in C++ for matrix operations. However, my compiler complains, where before it did not. This code was left on a shelf for six months and in between I upgrad...
Stank asked 24/1, 2009 at 16:34

4

Solved

I am trying to overload the c++ operator== but im getting some errors... error C2662: 'CombatEvent::getType' : cannot convert 'this' pointer from 'const CombatEvent' to 'CombatEvent &' this ...
Jointed asked 22/8, 2012 at 7:33

5

Solved

For example: in a C++ header file, if I defined a struct Record and I would like to use it for possible sorting so that I want to overload the less operator. Here are three ways I noticed in variou...
Colloquy asked 4/11, 2011 at 23:25

3

Solved

I would like to override the '=' operator for a CGFloat like the follow try : func = (inout left: CGFloat, right: Float) { left=CGFloat(right) } So I could do the following: var A:CGFloat=1 va...
Homogeny asked 30/4, 2015 at 9:38

1

Solved

Consider the struct S with two operator== overloads of same && qualifier and different const qualifier: struct S { bool operator==(const S&) && { return true; } bool operat...
Distiller asked 23/3, 2021 at 10:26

7

Say I want a C++ function to perform arithmetic on two inputs, treating them as a given type: pseudo: function(var X,var Y,function OP) { if(something) return OP<int>(X,Y); else if(somet...
Millisecond asked 15/8, 2009 at 21:37

3

Solved

Background I am using interface-based programming on a current project and have run into a problem when overloading operators (specifically the Equality and Inequality operators). Assumptions ...
Muldoon asked 8/4, 2009 at 3:32

1

Solved

I'm trying to test my project in the latest Visual Studio and Clang versions. One of the errors that pops up is related to an ambiguous operator (with reversed parameter order). This does not seem ...
Bartlett asked 28/1, 2021 at 23:53

1

Solved

Suppose I have a custom type wrapping an existing type, newtype T = T Int deriving Show and suppose I want to be able to add up Ts, and that adding them up should result in adding the wrapped valu...

4

Solved

In some books and often around the internet I see recommendations like "operator== should be declared as friend". How should I understand when an operator must be declared as friend and when it s...
Peg asked 6/6, 2011 at 17:35

1

Solved

Adding a dictionary to a list using the __iadd__ notation seems to add the keys of the dictionary as elements in the list. Why? For example a = [] b = {'hello': 'world'} a += b print(a) # -> ['h...
Preconception asked 9/12, 2020 at 23:50

6

Solved

I am beginner with the Swift having no advance knowledge with operators. I have the following class class Container { var list: [Any] = []; } I want to implement the operator subscript [] in o...
Courtroom asked 11/8, 2015 at 19:16

3

Solved

I have a class which allows for a vector to be created holding any type or class. However I'd like to add additional functionality for numerical types. template <> class Vec<double> : ...

1

Solved

The piece of code below dereferences a nullptr. struct Foo { int *bar; operator int&() { return *bar; } explicit operator bool() const { return bar; } }; int main() { Foo f {nullptr}; ...

4

Solved

Say I'm writing an int wrapper and need to provide every single operator overload. Must the author list out every single one, or can it auto-generate any based on what the author has provided...
Keavy asked 28/9, 2015 at 6:26

4

Solved

Suppose I wanted to overload the "==" operator for a derived class, do I need to rewrite the overload in the derived class header file or is there a way to implement the operator overload in the .c...
Unmoved asked 4/6, 2015 at 8:23

7

Solved

I wonder if operator!= is automatically provided when operator== is defined within my class? When I have operator== defined in class A, obviously A a, A b, a == b works, but a != b doesn't. However...
Mosira asked 24/7, 2014 at 15:52

7

Solved

Django by-default implements username as case sensitive, now for authentication I have written my own Authentication Backend to handle case insensitive usernames while authentication. As shown in ...
Inexpressive asked 2/11, 2012 at 7:1

11

Solved

As far as I know there is no way to do this, but I am going to ask just in case someone else knows how to do this. How can I declare a date as a const in Delphi? The only solution I have found is...
Betrothal asked 23/3, 2009 at 23:0

7

Solved

G'Day Mates - What is the right way (excluding the argument of whether it is advisable) to overload the string operators <, >, <= and >= ? I've tried it five ways to Sunday and I get vario...
Bueschel asked 6/4, 2010 at 19:20

2

Solved

I know it is possible by using traits to implement operator overloading in Rust. In C++ is also possible to have multiple operator overloading for the same operator and the same struct, and switch ...
Teressaterete asked 4/9, 2020 at 12:32

2

Solved

This is more of a curiosity question about C++ that came up after learning how to find the index referenced by an iterator. Given two vector iterators, why can they be subtracted from each other bu...

6

Solved

A somewhat little-known feature of C# is the possibility to create implicit or explicit user-defined type conversions. I have been writing C# code for 6 years now, and I have never used it. S...

© 2022 - 2024 — McMap. All rights reserved.