Interesting Syntax

Started by
17 comments, last by b2b3 18 years, 3 months ago
Quote:Original post by Sharlin
Well, using operator| to scale a vector isn't too obvious either.


yeah i suppose i missed that. i was only looking at the code inside the function.

yeah, thats bad alright...
Advertisement
const CVector operator | (const scalar_t length) const
{
return *this * (length / !(*this));
}

Does this even compile? That is, is it valid to use a this pointer if the method isn't within a class, like: "const CVector CVector::operator | ..."? If it is valid, then what exactly is this this-ing?
Quote:Original post by Sharlin
Woah, that's one hell of a WTF. Code like that is why some (mostly Java) people insist that operator overloading is an unconditionally bad feature.


Operator overloading (and even the ability to define new operators, which you can't really do in C++) has it's uses, but it can be abused very badly.
Quote:Original post by socrates200X
...Does this even compile?

It's probably a typo or defined inside the class -- otherwise it won't compile for a couple reasons. As you note, it should then be "CVector::operator |"

BTW, one reason for not using '|' for multiplication is that the precedence is wrong. What is the value of c below?
    CVector a( 1, 1, 1 );    CVector b( 2, 2, 2 );    CVector c = a + b|3; 
If you think it is [7, 7, 7], you are the victim of poorly designed operator overloading.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
The future lies in whitespace overloading.
How about this one:

char (*(*x())[])()

is a function returning a pointer to an array of pointers
to functions returning char


visit my website at www.kalmiya.com
Quote:Original post by JohnBolton
Quote:Original post by socrates200X
...Does this even compile?

It's probably a typo -- otherwise it won't compile for a couple reasons. As you note, it should be"CVector::operator |"


Not necessarily - it could be (and probably is) written inline inside the class declaration.

Quote:Original post by JohnBolton
Quote:Original post by socrates200X
...Does this even compile?

It's probably a typo or defined inside the class -- otherwise it won't compile for a couple reasons. As you note, it should then be "CVector::operator |"

BTW, one reason for not using '|' for multiplication is that the precedence is wrong. What is the value of c below?
    CVector a( 1, 1, 1 );    CVector b( 2, 2, 2 );    CVector c = a + b|3; 
If you think it is [7, 7, 7], you are the victim of poorly designed operator overloading.


They're not using it for multiplication but for normalization, if I understood it correctly. In which case they probably do want an operator with lower precedence than addition :
Quote:Original post by SamLowry
The future lies in whitespace overloading.


That's the most complicated April Fools joke I have ever seen [lol].

This topic is closed to new replies.

Advertisement