would this work

Hi all. I am currently trying to make a 2D library for a game I am making, one of the library's is going to be a 2D vector class. I want to be able to find length,magnitude,normalise,dot product and the basic +,-,=,== operation in this class

now for the question =D

would this type of set out work for my vector classes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef _VECTOR_2_H_
#define _VECTOR_2_H_

class Vector2
{
public:
	Vector2();

	Vector2(float a_x,float a_y); : x(a_x), y(a_y)	{}
	float x,y;

	~Vector2();

	//Addition
	const Vector2& operator +=(const Vector2 &RHS)
	{
		a_x += RHS.x;
		a_y += RHS.y;
		return *this;
	}

private:

protected:

};

#endif 
It's conventional for the operator to return a reference, not a const reference, that const it ok.

The approach is fine. Once you get it working, you could generalise it to support more than one dimension by using templates.
kk thanks for the help =D
Topic archived. No new replies allowed.