Okay, I'm writing a class, and I want to know how I can have two different + operators in the class.
Is it even possible to do this?
Thanks!
Okay, I'm writing a class, and I want to know how I can have two different + operators in the class.
Is it even possible to do this?
Thanks!
Yes, for different types of right-hand side arguments.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
So as long as they have different parameters, you can do it?
Isn't there also a uranary + operator analgalous to the uranary - operator? I could be very wrong about this...
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
++ and -- you mean?
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
"unary"
You mean a '+5' analogous to '-5' (for example)?
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Yeah, Zach knows what I'm thinking. Is that possible?
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
Yep.
Code:class A { public: A operator+(); // Unary +: A x; +x; A operator+(A b); // Binary +: A x, y; x + y; };
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
*fist pump*
And I suppose other things would go on this line...
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
Not that I don't have confidence in you, Zach, but I was almost sure that you were wrong. Then I checked and learned.Originally posted by Zach L.
Yep.
Code:class A { public: A operator+(); // Unary +: A x; +x; A operator+(A b); // Binary +: A x, y; x + y; };
Why is there a unary + operator? With the basic types, +x returns x. So why use +x at all?
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
+x = x if x is a number, however, c++ provides a way to overload + so you can use it to do whatever you want for your class, one of the features that I like in c++.
Thats good. Someone keeping me honest.Originally posted by pianorain
Not that I don't have confidence in you, Zach, but I was almost sure that you were wrong. Then I checked and learned.
I really can't see much use for it. If you're gonna use operators, they should logically work as you'd expect them (otherwise, use a named function), and I can't think of any logical place where +x != x. It was probably added to C++ since it is mathematically valid syntax.
Why is there a unary + operator? With the basic types, +x returns x. So why use +x at all?
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.