Overloading Unary Operator in C++ | C++ Tutorial | Mr. Kishore

  Рет қаралды 70,365

Naresh i Technologies

Naresh i Technologies

Күн бұрын

Пікірлер
@NareshIT
@NareshIT 5 жыл бұрын
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
@gloryofgames1607
@gloryofgames1607 5 жыл бұрын
//I get error #include using namespace std; class Abc { public: int a; ABC() { a=0; } void input() { couta; } void show() { cout
@4.otechnologysaikumar829
@4.otechnologysaikumar829 4 жыл бұрын
@@gloryofgames1607 me to broo...I have also error...
@ahadsun1188
@ahadsun1188 4 жыл бұрын
i have never seen any videos with this much details,hats off you Sir.....Respect 1000
@stockmarket_matrix
@stockmarket_matrix 6 жыл бұрын
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
@whoisnegii
@whoisnegii 5 жыл бұрын
please explain why it has to be done like that ?
@sunnyjain630
@sunnyjain630 5 жыл бұрын
Thank you!
@lemonpooh1764
@lemonpooh1764 5 жыл бұрын
thank you so much
@shashankgupta6700
@shashankgupta6700 3 жыл бұрын
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
@yuvrajsharma2134
@yuvrajsharma2134 4 жыл бұрын
Your teaching and content is very good. Really feels good to be on your channel.
@codingwithmx
@codingwithmx 5 жыл бұрын
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.
@JohnDoe-ej6vm
@JohnDoe-ej6vm 5 жыл бұрын
thanks a lot . but plz exmplain why we face error , and how parameter is working in this function ?
@shrishojha6490
@shrishojha6490 4 жыл бұрын
thanks , what sir is doing would be right if he would have been using pre increment operator
@troopIine
@troopIine 4 жыл бұрын
correct that's right
@HarishKumarC007
@HarishKumarC007 4 жыл бұрын
Wonderful, thanks a lot
@ekambaramsainikhil9301
@ekambaramsainikhil9301 3 жыл бұрын
we need to call the function as operator objectname eg: ++t where ++ is the operator and t is the object name
@ajaykharat8689
@ajaykharat8689 6 жыл бұрын
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
@arjumandayoub8483
@arjumandayoub8483 Жыл бұрын
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?
@iniyaviji2796
@iniyaviji2796 Жыл бұрын
Lovely sir thank u so much
@jaypatel9392
@jaypatel9392 4 жыл бұрын
Thank u sir for providing your valuable knowledge ❤️
@tayyabshahzad2747
@tayyabshahzad2747 3 жыл бұрын
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
@darshkatare8896
@darshkatare8896 8 ай бұрын
sir I scored good marks in practical exam because of you love u sir❤❤❤❤
@lincycarolinesagayam6726
@lincycarolinesagayam6726 4 жыл бұрын
It makes us feel easy
@sushantgupta4757
@sushantgupta4757 4 жыл бұрын
Thanku so much sir 😍😍
@aishwarya2860
@aishwarya2860 7 жыл бұрын
Excellent sir
@bs_it4975
@bs_it4975 3 жыл бұрын
Thanks sir!
@gopialavala8618
@gopialavala8618 2 жыл бұрын
sir in the place of a=0, with out using the zero it can be treated as the zero initial value
@harshavardhantp8308
@harshavardhantp8308 4 жыл бұрын
When we are defining the constructor. Do we have to define default constructor or will it define itself
@arslanbegmyradov3048
@arslanbegmyradov3048 4 жыл бұрын
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
@rambhaktuchihaobito7987
@rambhaktuchihaobito7987 2 жыл бұрын
Thank you bro
@mohitsaud2071
@mohitsaud2071 4 жыл бұрын
//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
@ernisrisatyavennela3523
@ernisrisatyavennela3523 4 жыл бұрын
can't we use pre increment operator for overloading?????
@dharmadevi9817
@dharmadevi9817 7 жыл бұрын
pls upload all java concepts.rly nice class
@vaishnavidubeyit_0309
@vaishnavidubeyit_0309 6 жыл бұрын
Sir in unary operator if we have to increment & decrement in two different values means suppose a++ & b-- so how we can use it .
@al-hadees6236
@al-hadees6236 3 жыл бұрын
there is small mistake in void main instead of t++ and t-- the correct way is ++t and --t
@ashishmishra-yu1jr
@ashishmishra-yu1jr 4 жыл бұрын
Sir here pre increment and pre decrement work not post increment/decrement
@unknownchannel1924
@unknownchannel1924 3 жыл бұрын
just change a++ to ++a and a-- to --a similarly for t also.
@shubhampandey1073
@shubhampandey1073 4 жыл бұрын
sir can we overload the += operator or not
@amitkumargupta6722
@amitkumargupta6722 4 жыл бұрын
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
@4.otechnologysaikumar829
@4.otechnologysaikumar829 4 жыл бұрын
Here postfix oparator using to become error sir......then output become when the prefix oparating using.........whyyy this happend sirr
@rakshith3458
@rakshith3458 7 жыл бұрын
Can we refine "+" operator to subtract two operands instead of addition using operator overloading ?
@milindmodi4762
@milindmodi4762 7 жыл бұрын
yes you can but only with user define data types.
@AryanRaj-gm6pu
@AryanRaj-gm6pu 5 жыл бұрын
yes you can do
@viswanathgupta7406
@viswanathgupta7406 7 жыл бұрын
load sessions on function overload sir
@rahmanullahshirzad7865
@rahmanullahshirzad7865 4 жыл бұрын
sir this is towice run but error what is problem?
@shubhampandey1073
@shubhampandey1073 4 жыл бұрын
sir this programme show an error in ide
@HarishKumarC007
@HarishKumarC007 4 жыл бұрын
So in comment section, they have changed please go once, even I faced same thing
@ravikishore1743
@ravikishore1743 6 жыл бұрын
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.
@venkatp9381
@venkatp9381 4 жыл бұрын
& refers to reference, so a reference of class complex is the return type. If i t is *, it is pointer to class complex
@sumanthkavikondala1036
@sumanthkavikondala1036 6 жыл бұрын
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.
@gamuchiraimureyani281
@gamuchiraimureyani281 6 жыл бұрын
actually the misleading person is you
@sumanthkavikondala1036
@sumanthkavikondala1036 6 жыл бұрын
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.
@smarttube1141
@smarttube1141 6 жыл бұрын
Yeah Correct bro...
@adityadubey408
@adityadubey408 6 жыл бұрын
yeah you are correct I found out the same error
@adityadubey408
@adityadubey408 6 жыл бұрын
shut the f*** up !
@arjunmenonkandanat6328
@arjunmenonkandanat6328 3 жыл бұрын
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++
Operator Overloading using Friend in C++ | C++ Tutorial | Mr. Kishore
15:46
Naresh i Technologies
Рет қаралды 78 М.
Operator Overloading in C++ Example 1 | C++ Tutorial | Mr. Kishore
31:48
Naresh i Technologies
Рет қаралды 229 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Cat mode and a glass of water #family #humor #fun
00:22
Kotiki_Z
Рет қаралды 42 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Overloading Insertion and  Extraction Operator in C++ | C++ Tutorial | Mr. Kishore
16:55
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
Constructor Overloading Example-1 | C++ Tutorial | Mr. Kishore
14:40
Naresh i Technologies
Рет қаралды 84 М.
Templates in C++
17:58
The Cherno
Рет қаралды 607 М.
Friend Function in C++ Part 1 | C++ Tutorial | Mr. Kishore
17:38
Naresh i Technologies
Рет қаралды 168 М.
Hardy's Integral
13:47
Michael Penn
Рет қаралды 18 М.
Constant Members in Class | C++ Tutorial | Mr. Kishore
20:04
Naresh i Technologies
Рет қаралды 55 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 337 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН