[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Buckys C++ Programming Tutorials – 51 – More on Operator Overloading
by
Tags:
Comments
48 responses to “Buckys C++ Programming Tutorials – 51 – More on Operator Overloading”
-
How do I make the same operator but for division?
-
watermelon.exe
-
Why do you use parentheses when you write return (brandNew); ? Just curious if that has a different effect or purpose here.
-
did you not need to overload the = assignment sign aswell ??
-
for the most recent versions of c++, you must declare the overloading as:
Sally Sally::operator+(Sally const& aso) in order to work -
This is a very good tutorial, thank you!!!
-
Diff between old languages and new ones.
Newer : learning to drive a car.
Older : building a car and learning to drive it -
This doesn't confuse me, as I already know .add, HOWEVER this would confuse a LOT of people who have religiously followed the series from 0 prior knowledge because he says "Well you already know you can do this .add," yada yada etc.. My question is: How would the average beginner viewer of these videos "already know" what you haven't even taught them? I've watched every video so far and not once prior to this video did he mention .add, so NO they WOULDN'T know that they can already do this. He's a great teacher, but leaves canyons-wide gaps in the basic learner's knowledge.
For anyone looking for another teacher who goes to great lengths to encapsule (;D) the entirety of c++ in your learning, I recommend Cave of Programming (For a sample, watch his video on Pointers and BE AMAZED at how much you just learned).
Learning Lad also helped me understand some stuff. 🙂
-
Nice job on choosing Fibonacci numbers!
-
pretty cool huh
-
I think the confusion most people will have :
– passing one object (b) instead of passing a and b
– this part " brandnNew.num = num + aso.num"
the single key "num" that is not referenced through an object like ( a.num)so somehow this "num" is "a.num" and the operator+ function just know that and add it ro aso.num ?
-
So when does the "Sally Sally::operator+(Sally aso) {}" function get called?
when you do c= a+b inside the main() fucntion? -
good stuff. it not an easy concept to grasp
-
why return(brandnew) with brackets ?
-
Can someone please help me understand this: at 4:08 he says it took the current object a, how does the program take a as the current object even though we created b and c after that ?
Thanks! -
i don't understand these class tutorials
-
The code below returns a very large negative value, anyone know why?
#include <iostream>
using namespace std;#define WAIT system("pause")
class Apple {
public:
Apple(int);
Apple();
Apple operator+(Apple);
int num;
};Apple::Apple(int a) {
a = num;
}Apple::Apple() {
}Apple Apple::operator+(Apple b){
Apple brandNew;
brandNew.num = num + b.num;
return (brandNew);
}int main() {
Apple a1(2);
Apple a2(2);
Apple c;
c = a1 + a2;
cout << "brandnew " << c.num << endl;
WAIT;
} -
Could (Sally aso) be replaced with (aso1 aso2)? Why is the first one sally but the second one can be anything?
-
I have written the code in one file
#include<iostream>
#include<conio.h>
#include<cstdlib>
#include<string>
using namespace std;
class sally{
public:
int num;
sally(int a){
num=a;
}
sally(){
}
sally operator+(sally aso){
sally brandnew;
brandnew.num=num+aso.num;
return (brandnew);
}
};
int main(){
sally a(23);
sally b(34);
sally c=a+b;
cout<<c.num;
} -
So using operator overloading we can perform mathematical operations on objects.
-Cool -
What is going to happen if I try to add two simple integers, for example? The way the operator works, after overloading it, affects just the objects or the simple processes, as well?
-
can anybody tell why are we creating constructors in overloading
-
I'm actually disappointed you don't use this more. I thought this concept was really cool. I like the idea of having more control over the default operations in my programs.
-
dam, this guy really objectifies women.
-
after i understood what operator overloading is with other ways, i come back to watch this video again. must to say, this video is really confusing and bad organised.
-
it took me a lot of .cpp files to understand this
-
Yo overloading has been eating my lunch in my Data Structures course. Thank you so much!
-
In Sally.cpp we have the function Sally(int a), which just assigns num to the value a. But why num gets automatically get assigned to a?, i.e. why this is enough to have a.num = 34?..I thought we have to put it "a.num = a", but this is wrong..why?
-
it's simple enough
-
I want a child from you, bucky
-
I got an unresolved external error
-
worst video in the series. what a shit example u used lmao
-
Just out of curiosity, why wouldn't it work if I say " Sally c() " when declaring c?
-
I hope this makes things clearer for people. I wrote similar but different code from Bucky's: _____________________________#include <iostream>
using namespace std;class Sally {
public:
int num; // Class variable.
Sally(int x) { // Class constructor.
num = x;
}
Sally operator+ (Sally aso) { // Not a class constructor. Sally is the return type.
aso.num = num + aso.num; // In other words, b.num = a.num + b.num. Note: .num is a object variable, not a function!
return aso; // Returns Sally object.
}
};int main()
{
Sally a = 5; //initializes through the constructor.
Sally b = 6;
a = (a + b); // the a object equals the returned object of the operator overload function.
cout << a.num << endl;
}Note: Doing it like this is discouraged. Had I declared more variables, num2, num3, for example, object a's variables would have taken on all the values of the b's variables, even without prompting them to do so by the overload function. -
brandNew . num = num + aso . num ; So, compiler automatically substitute c= a + b ? ; And one(b) should has object and one (a) shouldn't?
-
why should we add class name (sally) behind the function? Due to its function wanna to return an object?
-
If we initialized a newSally object in the operator function, how come we have to create a blank object in main?
-
Why do we write .num? It's not an object …?
-
Is this thing even useful now? I see no sense in adding 2 numbers in such a roundabout way..
-
It took me awhile to understand it.
-
So is this '+' getting called from 'a'?
-
not sure if anyone still replies to these videos, but why didnt he need to overload the "=" operator? ie when he used c = a + b, how did the compiler already know what to do with "=" ?
-
Why do we return brandNew and not brandNew.num?
-
Why did he put brandNew in paranthesys when he typed return (brandNew) ?
-
Why did he put brandNew in paranthesys when he typed return (brandNew) ?
Why was the a object equal to num ?
Why was the b object equal to aso ? Is C++ so smart that it automatically sets them equal to the objects ?
Why c was equal to brandNew? -
Question:
so when we use this statement c= a+b, it means we call the member function operator+ that belongs to object a and pass object b as its parameter and at the end it will return a new object and assign it to object c. But, if change the order, c =b+a, then it means we call the member function operator+ that belongs to object b and pass object a as its parameter and at the end it will return a new object and assign it to object c. Am I right? -
hi Bucky can you explain the different between the postfix and prefix operators
thnks
Leave a Reply