Please Comment, Subscribe and Click Bell🔔🔔🔔 Icon for More Updates. To learn software course from our experts please register here for online training: goo.gl/HIB0wL
The given example is post increment so the below is the way to write it: #include using namespace std; class test int a; public: { test() { a=20; } void operator++() { ++a; } void operator--() { --a; } void operator++(int ) { a++; } void operator--(int ) { a--; } void show() { cout
Generally operators are designed to work with pre-defined datatype. In order to use operator with user-defined datatype operator are overloaded. In operator overloading:- a. With Binary operator 2 objects are required(one implicit and other explicit) b. with Unary operator 1 object is required(one implicit on LHS) void operator ++() { a++; cout
It was two errors in this code: you need to correct: void operator ++ (int){a++;} and void operator -- (int){a--;} because the unary operator has only one implicit and it also an integer.
the reason for error can be explained as : The code you provided contains a compilation error because the `++` operator is overloaded as a prefix operator, but it is being used as a postfix operator in the `main` function. In C++, the `++` operator can be overloaded as both a prefix and a postfix operator. The prefix version of the `++` operator is declared by defining a member function with the signature `void operator++()`, while the postfix version is declared by defining a member function with the signature `void operator++(int)`. In your code, you have defined the prefix version of the `++` operator by declaring the member function `void operator++()`. However, in the `main` function, you are using the `++` operator as a postfix operator when you write `t++;`. This causes a compilation error because there is no matching overload for the postfix version of the `++` operator. To fix this error, you can either change the usage of the `++` operator in the `main` function to use it as a prefix operator (`++t;`) or define an overload for the postfix version of the `++` operator in your class. Is there anything else you would like to know?
//Actually the program for the post fix is // #include using namespace std; class Test { int a; public: Test() { a=0; } Test( int n) { a=n; } void operator ++(int) { a++; } void operator --(int) { a--; } void show() { cout
Sir you are the best .....I have seen so many videos of opeator overloading but did not get the concept and then i watched your video all concepts are clear.Thank you so much sir
you are a good instructor. t++ //Error because compiler treat it as binary operator. if one wants to run this , he/she must use it as binary operator. #include using namespace std; class fun{ public: int a; fun(int x):a(x) {} void operator - (int i) { a=a + i; cout
here is the code for this program..... #include using namespace std; class test { int a; public: test() { a=0; } void operator ++ (int) { ++a; } void operator -- (int) { --a; } void show() { cout
This code wont work, as you had overloaded the operator for prefix(pre-increment) and you were using postfix to call the overloaded function by ("t++") but instead "++t" would work. Where as postfix overloading is having a different syntax to do so by passing a dummy int as a argument. Sir please educate the correct information instead misleading the students. I understand that you are trying to educate students for free here but i feel its better not to teach at all instead of passing false information.
A concept is a standard which cant be manipulated by any individual apart from the creator. Because of people like you students are getting wrong information and they carry the same to others.
Why & is present in the declaration of the Operator ++ overloading in the blow code sir? Complex &Complex::operator ++(){ } Please suggest. Also i saw some code where * is used instead of & like belo Complex *Complex::operator ++() { } Please explain.
what he is telling is wrong. This program will be of pre increment operator. NOT post increment operator in main() , he has to write ++t , instead of t++
Please Comment, Subscribe and Click Bell🔔🔔🔔 Icon for More Updates. To learn software course from our experts please register here for online training: goo.gl/HIB0wL
//I get error
#include
using namespace std;
class Abc
{
public:
int a;
ABC()
{
a=0;
}
void input()
{
couta;
}
void show()
{
cout
@@gloryofgames1607 me to broo...I have also error...
The given example is post increment so the below is the way to write it:
#include
using namespace std;
class test
int a;
public:
{
test()
{
a=20;
}
void operator++()
{
++a;
}
void operator--()
{
--a;
}
void operator++(int )
{
a++;
}
void operator--(int )
{
a--;
}
void show()
{
cout
please explain why it has to be done like that ?
Thank you!
thank you so much
Generally operators are designed to work with pre-defined datatype. In order to use operator with user-defined datatype operator are overloaded.
In operator overloading:-
a. With Binary operator 2 objects are required(one implicit and other explicit)
b. with Unary operator 1 object is required(one implicit on LHS)
void operator ++()
{
a++;
cout
It was two errors in this code:
you need to correct:
void operator ++ (int){a++;} and void operator -- (int){a--;}
because the unary operator has only one implicit and it also an integer.
thanks a lot . but plz exmplain why we face error , and how parameter is working in this function ?
thanks , what sir is doing would be right if he would have been using pre increment operator
correct that's right
Wonderful, thanks a lot
we need to call the function as operator objectname eg: ++t where ++ is the operator and t is the object name
i have never seen any videos with this much details,hats off you Sir.....Respect 1000
the reason for error can be explained as :
The code you provided contains a compilation error because the `++` operator is overloaded as a prefix operator, but it is being used as a postfix operator in the `main` function.
In C++, the `++` operator can be overloaded as both a prefix and a postfix operator. The prefix version of the `++` operator is declared by defining a member function with the signature `void operator++()`, while the postfix version is declared by defining a member function with the signature `void operator++(int)`.
In your code, you have defined the prefix version of the `++` operator by declaring the member function `void operator++()`. However, in the `main` function, you are using the `++` operator as a postfix operator when you write `t++;`. This causes a compilation error because there is no matching overload for the postfix version of the `++` operator.
To fix this error, you can either change the usage of the `++` operator in the `main` function to use it as a prefix operator (`++t;`) or define an overload for the postfix version of the `++` operator in your class.
Is there anything else you would like to know?
//Actually the program for the post fix is //
#include
using namespace std;
class Test
{
int a;
public:
Test()
{
a=0;
}
Test( int n)
{
a=n;
}
void operator ++(int)
{
a++;
}
void operator --(int)
{
a--;
}
void show()
{
cout
Your teaching and content is very good. Really feels good to be on your channel.
Sir you are the best .....I have seen so many videos of opeator overloading but did not get the concept and then i watched your video all concepts are clear.Thank you so much sir
you are a good instructor.
t++ //Error because compiler treat it as binary operator.
if one wants to run this , he/she must use it as binary operator.
#include
using namespace std;
class fun{
public:
int a;
fun(int x):a(x)
{}
void operator - (int i)
{
a=a + i;
cout
whithout ERROR - Program should be:
class Sample
{
int a;
public:
Sample() { //default constructor
a = 0;
}
void operator++() {
a++; // implicit
}
void operator--() {
a- -; // implicit
}
void printValue() {
cout
Thank you bro
Lovely sir thank u so much
sir I scored good marks in practical exam because of you love u sir❤❤❤❤
Thank u sir for providing your valuable knowledge ❤️
It makes us feel easy
Thanku so much sir 😍😍
Excellent sir
sir in the place of a=0, with out using the zero it can be treated as the zero initial value
here is the code for this program.....
#include
using namespace std;
class test
{
int a;
public:
test()
{
a=0;
}
void operator ++ (int)
{
++a;
}
void operator -- (int)
{
--a;
}
void show()
{
cout
When we are defining the constructor.
Do we have to define default constructor or will it define itself
Thanks sir!
can't we use pre increment operator for overloading?????
Sir in unary operator if we have to increment & decrement in two different values means suppose a++ & b-- so how we can use it .
This code wont work, as you had overloaded the operator for prefix(pre-increment) and you were using postfix to call the overloaded function by ("t++") but instead "++t" would work. Where as postfix overloading is having a different syntax to do so by passing a dummy int as a argument. Sir please educate the correct information instead misleading the students. I understand that you are trying to educate students for free here but i feel its better not to teach at all instead of passing false information.
actually the misleading person is you
A concept is a standard which cant be manipulated by any individual apart from the creator. Because of people like you students are getting wrong information and they carry the same to others.
Yeah Correct bro...
yeah you are correct I found out the same error
shut the f*** up !
there is small mistake in void main instead of t++ and t-- the correct way is ++t and --t
just change a++ to ++a and a-- to --a similarly for t also.
Sir here pre increment and pre decrement work not post increment/decrement
Here postfix oparator using to become error sir......then output become when the prefix oparating using.........whyyy this happend sirr
pls upload all java concepts.rly nice class
Why & is present in the declaration of the Operator ++ overloading in the blow code sir?
Complex &Complex::operator ++(){ }
Please suggest.
Also i saw some code where * is used instead of & like belo
Complex *Complex::operator ++() { }
Please explain.
& refers to reference, so a reference of class complex is the return type. If i t is *, it is pointer to class complex
Can we refine "+" operator to subtract two operands instead of addition using operator overloading ?
yes you can but only with user define data types.
yes you can do
sir can we overload the += operator or not
load sessions on function overload sir
sir this programme show an error in ide
So in comment section, they have changed please go once, even I faced same thing
sir this is towice run but error what is problem?
what he is telling is wrong. This program will be of pre increment operator. NOT post increment operator
in main() , he has to write ++t , instead of t++