operator-overloading Questions
6
Solved
What is a recommended way to overload the output stream operator? The following can not be done. It is expected that compilation will fail if the operator << is not defined for a type T.
tem...
Rianon asked 2/11, 2010 at 12:28
5
Solved
Is it possible to overload C++ class operators in the static context? e.g.
class Class_1{ ... }
int main()
{
Class_1[val]...
}
Elkeelkhound asked 7/9, 2009 at 18:55
4
Solved
I'm new to overloading operators, I did some search and found this helpful article, I wrote my own code like the author did but I get vector vector::operator*(float, vector) must take either zero o...
Reareace asked 24/11, 2012 at 18:44
1
Solved
c++23 introduced static versions of the operator () and operator []:
#include <iostream>
#include <format>
struct S
{
static int operator()(int a, int b) { return a + b; }
static int...
Guesthouse asked 28/3, 2023 at 16:6
1
Solved
I have an error I don't understand.
The following snippet compiles
#include <iostream>
class Foo
{
std::string m_name;
public:
explicit Foo(std::string const& name):m_name{name}{}
...
Washburn asked 3/3, 2023 at 10:22
5
Solved
I have a struct that I'd like to output using either 'std::cout' or some other output stream.
Is this possible without using classes?
Thanks
#include <iostream>
#include <fstream>
tem...
Vale asked 27/4, 2010 at 6:23
4
Solved
I am a bit confused about the differences between
Type operator + (const Type &type);
Type &operator += (const Type &type);
and
friend Type operator + (const Type &type1, const ...
Trifid asked 11/1, 2011 at 0:4
3
Solved
If I am creating my own class in Python, what function should I define so as to allow the use of the in operator, e.g.
class MyClass(object):
...
m = MyClass()
if 54 in m:
...
See also What d...
Funderburk asked 7/2, 2010 at 14:8
7
Solved
I just discovered the bitwise complement unary operation in Python via this question and have been trying to come up with an actual application for it, and if not, to determine if it's generally sa...
Katowice asked 8/7, 2016 at 16:54
7
Solved
I'm attempting to use extension methods to add an operater overload to the C# StringBuilder class. Specifically, given StringBuilder sb, I'd like sb += "text" to become equivalent to sb.Append("tex...
Demivolt asked 5/10, 2008 at 20:59
3
I have a topic I'm confused on that I need some elaborating on. It's operator overloading with a const version and a non-const version.
// non-const
double &operator[](int idx) {
if (idx < ...
Baumann asked 8/10, 2013 at 1:5
12
Solved
Given a generic class definition like
public class ConstrainedNumber<T> :
IEquatable<ConstrainedNumber<T>>,
IEquatable<T>,
IComparable<ConstrainedNumber<T>>...
Carley asked 16/4, 2009 at 16:33
6
Solved
I am trying to implement a generic operator like so:
class Foo
{
public static T operator +<T>(T a, T b)
{
// Do something with a and b that makes sense for operator + here
}
}
Really...
Issuant asked 6/5, 2011 at 0:23
4
Solved
For the following generic c# class, I'd like to convert T to K:
public abstract class ValueType<T,K> : IValueType<T> where K : ValueType<T,K>,new()
{
public abstract T Value { ...
Moving asked 14/5, 2011 at 12:33
8
Solved
In C++, the concept of returning reference from the copy assignment operator is unclear to me. Why can't the copy assignment operator return a copy of the new object? In addition, if I have c...
Ole asked 23/6, 2010 at 21:45
7
Solved
How to define operator< on n-tuple (for example on 3-tuple) so that it satisfy strict weak ordering concept ? I know that boost library has tuple class with correctly defined operator< ...
Maxillary asked 11/6, 2009 at 7:22
1
Solved
In Haskell, we can write
print $ abs $ 3 - 5
using $ .
In F#, we can write
printfn "%d" << abs <| 3 - 5
However, in many cases in F#, it would be also useful to have the same fun...
Drifter asked 7/9, 2022 at 19:14
6
Solved
As I read in books and in the web, in C++ we can overload the "plus" or "minus" operators with these prototypes (as member functions of a class Money):
const Money operator +(const Money& m2) ...
Perk asked 31/1, 2014 at 16:42
4
Solved
What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but in...
Dmso asked 29/9, 2008 at 5:37
6
Solved
I was looking for a solution to write to a file and the console at the same time. I found a nice solution here.
As I am working pre C++11 I had to make a small change to the code from Lightness Ra...
Opinionated asked 28/6, 2016 at 11:28
2
Solved
In the code, why is (10 != i) calling == instead of !=? The other two call !=
#include <iostream>
class Integer
{
int x;
public:
bool
operator== (const Integer &i)
{
std::cout <...
Germayne asked 7/7, 2022 at 9:41
2
I need to implement a DNA class which has attribute a sequence which consists of a string of characters from the alphabet ('A,C,G,T') and I need to overload some operators like less than, greater t...
Shied asked 17/3, 2013 at 14:0
8
Solved
I am trying to write a piece of code for fun using C++ templates.
#include <iostream>
#include <vector>
template <class Container>
std::ostream& operator<<(std::ostrea...
Burseraceous asked 20/7, 2009 at 15:21
2
Solved
From this former question When all does comma operator not act as a comma operator?, I understood that commas inside a function call can only act as expression sperator. But from the code below, it...
Herzberg asked 19/12, 2017 at 13:38
5
Solved
I get to know about the Invoke operator that,
a() is equivalent to a.invoke()
Is there anything more regarding Invoke operator than please explain. Also, I did not get any example of Invoke operato...
Peaceful asked 18/7, 2017 at 17:41
© 2022 - 2024 — McMap. All rights reserved.