Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / in need of a quick check of my simple code

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th Mar 2010 22:45
The first project I did in c++ worked... but in retrospect it was horrible not object oriented. >.> I thought classes and structs were pretty much the same as user defined types in DBPro...

Since then, I've taken a java class, and I've made a bunch of object-oriented things in java, and I get it. Now, moving back to c++, I need to check my work.

I've made a basic 2d vector class, with operator overloading, to be able to do vector math easily. My question is: Does the following code follow standard conventions, handle stuff safely, and most importantly, does it work?



The biggest thing I'm worried about is assignment /= operators.
Is it fine, and do you have any recommendations of fixes?


dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 21st Mar 2010 05:24 Edited at: 21st Mar 2010 05:25
Operators such as +, -, /, * etc should be const because they (probably)won't modify the class, same for the length() function, other than this it looks fine. You may also want to make global operators to handle scenarios such as: 13.37f * myVector, currently only the inverse will work.

Login to post a reply

Server time is: 2024-10-02 01:36:51
Your offset time is: 2024-10-02 01:36:51