Skip to main content

All Questions

Tagged with
0 votes
1 answer
78 views

Use defined operators from base class in inherited class

Assume I have a base class class Vector { public: Vector(const std::vector<float> &elements); static Vector add(const Vector &v1, const Vector &v2); Vector Vector::...
vtx22's user avatar
  • 25
0 votes
0 answers
22 views

How do I define a custom method for @ operator? [duplicate]

Numpy uses the @ operator for matrix multiplication between two arrays. I have my own class for which I want to define a method using the @ operator. How should this be done? I define my own __add__, ...
johann's user avatar
  • 16
0 votes
1 answer
133 views

Custom nested class iterator for STL data structure

#pragma once #include <memory> #include <vector> #include <random> #include <list> class City; class MemberReport; class CityReport { private: City* mCity; protected: ...
notimportant's user avatar
0 votes
1 answer
58 views

how to fix no viable overloaded '=' in cpp

class Gebot{ string name; int betrag; public: Gebot(string name, int betrag = 100) : name{name} , betrag{betrag} { //ganze Zahl >0 und <=10.000.000 if(name.size() ==0 || betrag ...
OrneFixe's user avatar
0 votes
1 answer
122 views

Is it possible to inherit all operators in C++?

One can inherit all constructors of a base class using following code: class DerivedClass : public BaseClass { public: using BaseClass::BaseClass; ... }; Is it possible to inherit all ...
 Starodub_A_V's user avatar
1 vote
1 answer
110 views

How to overload the add operator to return the length of two string when they are added?

I am trying to create a class diffStr that behaves like str except, when a user tries to add or multiply two strings, the output is the length of each string added or multiplied (respectively). My ...
Harsh Darji's user avatar
-2 votes
1 answer
38 views

Can't multiply two matrices, where hight and width are defined by template

I wrote Class Matrix, parameters of which I define by template. So when I tried to declare operator* between two matrices, I found out? that Cpp counts matrices with different parameters as different ...
Kruzenger's user avatar
0 votes
0 answers
245 views

C++ Overloading insertion operator<< in class member function [duplicate]

I'm new to coding, but basically my assignment is to play the card game war and overloading operators to do so. So my question is how to overload the insertion operator when it is a class member ...
nickeno3's user avatar
1 vote
0 answers
137 views

Why am I getting a compilation error when overloading the insertion operator <<?

I am new to C++ (coming from Python and C) so operator overloading is completely new to me. I have been trying to overload the << operator to be able to represent a string version of a vector ...
Gregor Hartl Watters's user avatar
-1 votes
1 answer
37 views

Why does the += operator with lists alters the output of my function inside a class in python? [duplicate]

Hello I was trying to debug an issue with some classes and I came to this minimal example: class parentclass: a = ["a", "a"] b = ["b", "b"] def ...
nck's user avatar
  • 2,041
-1 votes
1 answer
67 views

Why can I pass a String and a StringBuilder references to the '+' opereator, but not other objects

I have a Person object.If I try to pass this object along with a reference to an Integer wrapper class to the '+' operator, I get an error because they arent of the same dataype. But if I have a ...
abc123's user avatar
  • 159
0 votes
1 answer
48 views

Returning the value of a +/- operator as a prefix with no actual value to add or subtract on a class object?

How would I be able to use a +/- operator on a class object when there is no actual value that I am adding or subtracting from? I would assume that the actual value is 0 from a sample code: x = 2.5 ...
newbiecoder11's user avatar
2 votes
1 answer
129 views

Assigning an operation to a special character within a class in Python [duplicate]

So, numpy can call its method "matmul" when multiplying 2 numpy arrays [1] by using the "@" character: import numpy as np a = np.array([1,2,3]) b = np.array([4,5,6]) a@b My ...
goktrenks's user avatar
0 votes
0 answers
51 views

How to overload operators in c++ [duplicate]

#include <iostream> #include <string> class TOperator { private: string name; public: TOperator(string name) { this->name = name; } TOperator(); void setName(string name) { ...
hurricanek218's user avatar
-1 votes
1 answer
1k views

C++ operator overload for another class ( object and operator from class A usinng data from class B

I'm new to C++ classes, objects and especially overcharging operators. Given the following main function, I have to work around it, so that in the end, the program will compile and run correctly. Here ...
Vlad's user avatar
  • 91

15 30 50 per page
1
2 3 4 5
10