Комментарии:
please explain layman term in insertion and extraction overloading , kindly i can't understand .please listen my voice.
ОтветитьHow do we overload insertion and extraction operators as a member function inside a class? This explanation works wonderful, but when I try to put it as member function in a class, it says that there is no match for the operator <<
ОтветитьHave a question : why would i use this instead of adding a method to print out each object?
ОтветитьGreat video! Thanks a lot!
ОтветитьDear bro, I just did it the get line overload and it works. Thank you bro. I just started learning C++ by watching your tutorials. Yeahhhhh
istream& getline (istream &input,User &user) //extration operator syntax getline(note: reference at object)
{
getline(input,user.first_name);
getline(input,user.last_name);
return input;
}
Great stuff
Ответитьi have a question, is there any way to return ostream without returning reference, i kno this is useless but i just wanna kno
ОтветитьExtraction? More like extraction of ignorance, and replacement with knowledge! Thanks again so much for this wonderful tutorial series.
ОтветитьI had to go over this a couple times, which was well worth it, as I walked away with an understanding of operator overloading, rather than to put it off until later. Yet another tool in the arsenal in the C++ language thanks to Caleb Curry's tutorial. Thank you, sir.
ОтветитьI see another example in my school,
as public member of class ___ void operator << ( ostream &);
and later in main program call just that obiect ___ cout << kogel ;
function class __ void kogel::operator << ( ostream &OS ){ OS << " example " << diameter ;}
Is not easier to just create instance in side of class?? Why everybody are creating overloaded ostream outside of class??
What is difference between your example and creating overloaded operator in side in class?
This is gold.
Ответитьfirst vid that actually explains each of the keywords and symbols for the operator overload instead of just writing the overload with no further elaboration. <3
ОтветитьThis was actually less confusing than the previous video.
ОтветитьFor people who got the error "Too many parameters for this operator function"
Declare the function in the class as a friend, and then define the function outside of the class. Example:
class Position
{
public:
int x = 10;
int y = 20;
friend std::ostream& operator << (std::ostream& output, Position user);
private:
};
std::ostream& operator << (std::ostream& output, Position user)
{
output << "x" << user.x << "y" << user.y;
return output;
}
int main()
{
}
Why can't we do copies of the ostream? I know it's bad practice but would it even be possible?
ОтветитьYou made it as easy as a piece of cake for me as a beginner.
liked and subscribed.
Another way of doing the istream operator overload:
istream &operator >> (istream &input, User &user)
{
cout << "What should " << user.first_name << user.last_name << "'s new first name be?";
input >> user.first_name;
cout << "What should " << user.first_name << user.last_name << "'s new last name be?";
input >> user.last_name;
cout << "What should " << user.first_name << user.last_name << "'s new status name be?";
string temp_status;
input >> temp_status;
user.set_status(temp_status);
return input;
}
When I add in User into the operator overloading function parameter, I get the error "too many parameters for this operator function", but when I add it in a friend, this error goes away. Can someone explain why this is happening?
ostream& operator << (ostream& output, User user){
return output;
}
This is not compiling
Actually you can use previous example:
Position y;
y.y = 5;
cout << "What the new value of Y"<<endl;
//Compiler know how to insert y value to y
cin >> y;
//y is updated to user input value
cout << y << endl;
really like your explanation
I tried the input without returning anything (with a void type) and it worked. Is it supposed to be done like I did?
ОтветитьThis tutorial series is great I have been following along since the first tutorial and I learned a lot.
Ответитьthank your for this, I didn't really know what my teacher was teaching until this
ОтветитьThe second parameter of extraction overloading function is passed by reference.
Does this mean that the reference allows us to change an user object to another?