operator-overloading Questions
3
Solved
I am trying to assign a custom type as a key for std::map. Here is the type which I am using as key:
struct Foo
{
Foo(std::string s) : foo_value(s){}
bool operator<(const Foo& foo1) { ret...
Palliasse asked 25/5, 2009 at 10:51
2
I am looking to accomplish the following:
int x, y, z;
foo[x] = y; acts like do_this(x,y);
z = foo[x]; acts like z = do_that(x)
I can accomplish the first with a Foo class and a Helper class, w...
Electrotherapy asked 25/7, 2020 at 20:15
1
I'm trying to understand the new default comparison operators introduced in C++20. My issue is about when an explicitly defaulted comparison operator gets implicitly defined. The following code exa...
Homogeneity asked 17/7, 2020 at 13:27
10
Solved
I have next code:
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
//namespace std
//{
std::ostream& operator << ( std::ostream& ...
Gredel asked 11/3, 2009 at 11:6
2
Solved
Is it possible to overload the index[] syntax for a collection/iterable type? for example I am writing a SortedList<T> class that wraps around a standard List<T>. and I'd just like to p...
Pyroelectric asked 28/10, 2013 at 19:43
3
Solved
I am relatively new to CPP and have recently stumbled upon std::variant for C++17.
However, I am unable to use the << operator on such type of data.
Considering
#include <iostream>
...
Ernaernald asked 13/6, 2020 at 4:42
6
Solved
I have used the following code for assignment operator overloading:
SimpleCircle SimpleCircle::operator=(const SimpleCircle & rhs)
{
if(this == &rhs)
return *this;
itsRadius = rhs...
Intro asked 9/4, 2012 at 16:26
3
Solved
I don't understand the compilation error C2676
for the below code
#ifndef __VEC_3D_H__
#define __VEC_3D_H__
#include <vector>
#include <cmath>
namespace Internal
{
/** very simple...
Caribbean asked 22/11, 2018 at 11:13
1
Solved
Consider this code:
#include <iostream>
#include <compare>
class A {
public:
int i = {};
std::strong_ordering operator<=> (A const& r) const
{
return i <=> ...
Racialism asked 28/4, 2020 at 19:25
3
Solved
As long as new issues are growing out of my previous question Overloaded assignment operator causes warning about recursion, I was legitimately urged to post this as new one. I have a reference cla...
Gerladina asked 26/12, 2011 at 12:38
4
Solved
Would you consider this evidence of bad design?
//FooType and BarType not in the same hierarchy
bool operator==(const FooType &, const BarType &);
bool operator<(const FooType &, co...
Broadus asked 2/7, 2013 at 20:59
16
Solved
One of my pet hates of C-derived languages (as a mathematician) is that
(-1) % 8 // comes out as -1, and not 7
fmodf(-1,8) // fails similarly
What's the best solution?
C++ allows the po...
Sequoia asked 23/10, 2010 at 9:10
4
Solved
I've already gone through question
I understand that, it is necessary to implement ==, != and Equals().
public class BOX
{
double height, length, breadth;
// this is first one '=='
public st...
Umbel asked 23/8, 2014 at 11:46
6
Solved
Is it possible to overload the null-coalescing operator for a class in C#?
Say for example I want to return a default value if an instance is null and return the instance if it's not. The code wo...
Sneaking asked 8/12, 2008 at 10:10
5
Solved
Is it possible to override the equivalence comparison in Javascript?
The closest I have gotten to a solution is by defining the valueOf function and invoking valueOf with a plus in front of the ob...
Hinda asked 10/5, 2012 at 18:18
2
Solved
c# lets you override "operator true" and "operator false" for a class:
class Foo
{
bool Thing;
Foo(bool thing)
{
Thing = thing;
}
public static bool operator true(Foo foo) => foo.Thing;...
Borrow asked 13/3, 2020 at 17:12
1
I have a custom class implementing __add__ and __radd__ as
import numpy
class Foo(object):
def __init__(self, val):
self.val = val
def __add__(self, other):
print('__add__')
print('type se...
Pogy asked 29/8, 2017 at 19:40
2
Solved
In C++ you can create templated classes that use a particular operator on the
templated objects and the class from which these objects are instantiated
must overload that particular operator for it...
Situla asked 26/2, 2020 at 17:45
3
Solved
I'd like to add a timestamp to certain outputs to the std::cout / std::cerr ostreams, without using modified standard streams, like so:
std::cerr << timestamp << "Warning!\n";
or so:...
Calices asked 23/1, 2020 at 17:11
2
Solved
I have a simple unit-test using Catch 2.11.1:
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <utility>
#include <any>
namespace A::B
{
namespace C
{
struct S
{
};
}
u...
Fiske asked 16/1, 2020 at 13:20
3
I am dealing with code that has been written not by me. I have this statement:
// p is type of std::unique_ptr<uint8_t[]>
if (p < 0) { /* throw an exception */ }
So what does p < 0 m...
Bedside asked 15/1, 2020 at 17:51
0
I am working my way through Barnes' book 'Programming in Ada 2012'. This is a code sample implementing a stack from section 12.5.
src/stacks.adb: (the main relevant file)
package body Stacks is
...
Yam asked 19/12, 2019 at 13:24
5
Solved
I want to achieve something like this:
class TestClass {
someMethod(stringParameter: string): void {
alert("Variant #1: stringParameter = " + stringParameter);
}
someMethod(numberPa...
Vite asked 2/10, 2012 at 10:3
2
I am trying to built a templated num class. This class needs to have a public attribute, val, with type T, which is the only templated parameter. Furthermore if one provides a value the attribute (...
Quest asked 9/12, 2019 at 21:13
2
Solved
Using the following code:
use v6d;
# sub circumfix:<α ω>( @a ) {
# @a[0] >= @a[1] & @a[0] <= @a[2];
# };
sub circumfix:<α ω>( $a, $b, $c ) {
$a >= $b & $a <= $c;...
Cantharides asked 8/12, 2019 at 19:59
© 2022 - 2024 — McMap. All rights reserved.