Interesting Syntax
Please explain the syntax of the following:
bool (*grid)[4][4];
I imagine two possibilities:
1. grid is a pointer to 4x4 array of boolean values.
2. grid is a 4x4 array of bool pointers.
3. grid is a pointer to an array of bool pointers, each pointing to an array of 4 boolean values.
Thanks for your help.
while were on this topic what the hell is this:
const CVector operator | (const scalar_t length) const{ return *this * (length / !(*this));}
I say 3.
Forevernoob, you could at least wait for Phineas to get an answer before hijacking his thread.
Forevernoob, you could at least wait for Phineas to get an answer before hijacking his thread.
grid is a pointer to a 4x4 array of bool pointers, e.g.
bool (*grid)[4][4];bool agrid[4][4];grid = &agrid;
Quote:Original post by spoulson
I say 3.
Forevernoob, you could at least wait for Phineas to get an answer before hijacking his thread.
I didnt mean to hijack, sory. Anyways afew months ago someone told me I must understand that code before i could join their team and I still have no clue what the hell it is.
Quote:Original post by ForeverNoobie
while were on this topic what the hell is this:const CVector operator | (const scalar_t length) const{ return *this * (length / !(*this));}
Simple:
*this dereferences "this" and enables the use of the class' overloaded operators without using "->".
If you don't dereference "this", you'd have to use the following syntax to invoke the overloaded operators:
const CVector operator | (const scalar_t length) const{ return this->operator * ( length / this->operator !( ) );}
Your code sample, btw. messes the operator semantics up in a horrible way[smile]. If you mean what the code does - it sets the length of CVector to the value specified by the "length" parameter (assuming the unary ! operator returns the length of the vector and "*" denotes scalar multiplication).
Cheers,
Pat.
Quote:Original post by ForeverNoobie
while were on this topic what the hell is this:const CVector operator | (const scalar_t length) const{ return *this * (length / !(*this));}
I'd say it's a good example of what Not to do with operator overloading.
It looks like it sets the length of a vector to the value specified, by scaling it. The assumption with this though is that the ! operator has been overloaded to return the current vector length.
In my opinion though this kind of operator overloading is a bad coding technique as it's so ambiguous. Much better to have a properly named function to do that same thing.
To be honest, I recon you're better off not joining the team that wrote that anyway :)
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.
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.
its just the use of operator!() that is confusing. the others( operator*, operator/ ) are okay.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement