All Questions
Tagged with operators overloading
124
questions
-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 ...
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 ...
-3
votes
2
answers
353
views
C++ no match for ‘operator=’
I've created a class to simulate the behavior of vector of int, because every time I read or write some value, also a read and write counter should be incremented to keep track of its usage. I can’t ...
4
votes
1
answer
189
views
Overload assignment operator and rule of zero [duplicate]
I have written a template class A<T> and I am making use of the rule of zero (I let the compiler generate the destructor, copy/move constructors and assignment operator overloadings).
However, I ...
1
vote
0
answers
85
views
Overloading operator&& it's return type
I have the following general class:
class Example
{
public:
Example(std::string _a): a(_a) {}
std::string a;
}
I want to overload the operator&& and || to be able to do something like ...
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) { ...
-1
votes
1
answer
214
views
operator overloading abstract class
There is an Student abstract class, and two derived class Grad and Undergrad; and I want to overload operator in several ways.
student.h
class Student {
protected:
string Name;
int Stu_num;...
0
votes
2
answers
683
views
how to overload + operator to add two queues?
I want to add two queues I have defined, what's wrong with my overloading method ?
I have tried the exact syntax of operator overloading but it did not work !!
These queues are dynamic arrays that we ...
0
votes
0
answers
34
views
C++ Can someone explain me this << and >> operation overloaded for showing a class content?
I hope this question don't get banned to me.
It's a knoob question, but i don't know how the things are working here.
I have the following istream and ostream overloaded << and >> ...
2
votes
1
answer
195
views
My pre increment is working fine but not the post increment
I have implemented the following class and tried to overload the pre and post-increment operator along with the extraction '>>' operator. The programs runs fine till 'cout << ++num1;' but ...
-2
votes
1
answer
56
views
extended assignment statements in Python [closed]
How can I add extended operators(below). Generally speaking how can I implement such an operator (for example only one).
X+=Y
X-=Y
X*=Y
X\=Y
X%=Y
X&=Y
X**=Y
X=Y
X—=Y
X//=Y
X<<=Y
X<&...
1
vote
1
answer
59
views
How can I overload these operators to make this program work?
To keep things simple, this is my class assignment: Add the following functions to the Cspinner class.
Overload the equal sign to compare two spinners. The following instruction should be valid if w1,...
0
votes
0
answers
24
views
C++ Overloading "<<" operator twice [duplicate]
I would like to overwrite the "<<" operator three times.
Bottle 2 should give bottle 1 some water.
For example:
Bottle bottle1(200);
Bottle bottle2(200);
bottle1 << 200 << ...
0
votes
1
answer
122
views
Overloading an operator to return areas
I'm trying to overload 2 operators. I want to overload the '*' operator to return the area of two intersected rectangles. Then, I'm trying to overload the '+' operator to find the sum of the areas of ...
1
vote
2
answers
43
views
I have overloaded << and = operators. Why when I assign an object to another and try to print it I get junk printed out?
I have a program with a class Length. This class has an attribute named size of type int and a dynamic
array *numb of type char. I have overloaded operators << and = so that I can print object ...