Jump to content
  • Advertisement
Sign in to follow this  
Phineas

Interesting Syntax

This topic is 4626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!