Sign in to follow this  

Structs or Classes to Represent Coordinates

This topic is 2417 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

I'd be interested in hearing anyone's opinion on the pros and cons of representing coordinates (or more generally any vector) either as a struct or as a class in C++. It's such a fundamental data type for game programming, so I thought some people might have ideas or experiences they could share regarding having used one or the other and what difference it made in a game engine for ease of coding and/or performance. Is there any consensus on whether one is definitively better, or does it just boil down to personal preference?

[code]typedef struct vector2D
{
float x;
float y;
} vector2D_t;

// OR

class Vector2D
{
private:
public:
Vector2D(float x, float y);
float x;
float y;
};[/code]

Thanks.

Share this post


Link to post
Share on other sites
Ah, I see. Even down to the member functions apparently, which I didn't know structs could also have.

Question withdrawn. Sorry.

Share this post


Link to post
Share on other sites
Just to add, structs in C++ can be defined in the same way as classes:

[code]struct Vector2D
{
...

};[/code]

So no need for the typedef.

Share this post


Link to post
Share on other sites
you might be best using directx D3DXVECTOR2 for this , cause all the operators are overloaded, makeing maths so mauch easyer

Share this post


Link to post
Share on other sites
[quote name='thedodgeruk' timestamp='1307289511' post='4819781']
you might be best using directx D3DXVECTOR2 for this , cause all the operators are overloaded, makeing maths so mauch easyer
[/quote]
What if the OP isn't using DirectX/Direct3D, or is targeting platforms that don't support it?

(I didn't see anything in the OP's posts specifying what APIs are being used or what platforms are being targeted.)

Share this post


Link to post
Share on other sites

This topic is 2417 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this