Bladeren bron

Fix operator[]

Daniele Bartolini 12 jaren geleden
bovenliggende
commit
1b88403ed5
4 gewijzigde bestanden met toevoegingen van 6 en 6 verwijderingen
  1. 3 3
      engine/core/math/MathTypes.h
  2. 1 1
      engine/core/math/Vector2.h
  3. 1 1
      engine/core/math/Vector3.h
  4. 1 1
      engine/core/math/Vector4.h

+ 3 - 3
engine/core/math/MathTypes.h

@@ -41,8 +41,8 @@ struct Vector2
 	Vector2(float nx, float ny);
 	Vector2(const float v[2]);
 
-	float operator[](uint32_t i) const;
 	float& operator[](uint32_t i);
+	const float& operator[](uint32_t i) const;
 
 	Vector2& operator+=(const Vector2& a);
 	Vector2& operator-=(const Vector2& a);
@@ -60,8 +60,8 @@ struct Vector3
 	Vector3(float nx, float ny, float nz);
 	Vector3(const float v[3]);
 
-	float operator[](uint32_t i) const;
 	float& operator[](uint32_t i);
+	const float& operator[](uint32_t i) const;
 
 	Vector3& operator+=(const Vector3& a);
 	Vector3& operator-=(const Vector3& a);
@@ -80,8 +80,8 @@ struct Vector4
 	Vector4(float nx, float ny, float nz, float nw);
 	Vector4(const float v[3]);
 
-	float operator[](uint32_t i) const;
 	float& operator[](uint32_t i);
+	const float& operator[](uint32_t i) const;
 
 	Vector4& operator+=(const Vector4& a);
 	Vector4& operator-=(const Vector4& a);

+ 1 - 1
engine/core/math/Vector2.h

@@ -218,7 +218,7 @@ inline Vector2::Vector2(const float a[2]) : x(a[0]), y(a[1])
 }
 
 //-----------------------------------------------------------------------------
-inline float Vector2::operator[](uint32_t i) const
+inline const float& Vector2::operator[](uint32_t i) const
 {
 	CE_ASSERT(i < 2, "Index must be < 2");
 

+ 1 - 1
engine/core/math/Vector3.h

@@ -241,7 +241,7 @@ inline Vector3::Vector3(const float v[3]) : x(v[0]), y(v[1]), z(v[2])
 }
 
 //-----------------------------------------------------------------------------
-inline float Vector3::operator[](uint32_t i) const
+inline const float& Vector3::operator[](uint32_t i) const
 {
 	CE_ASSERT(i < 3, "Index must be < 3");
 

+ 1 - 1
engine/core/math/Vector4.h

@@ -239,7 +239,7 @@ inline Vector4::Vector4(const float a[4]) : x(a[0]), y(a[1]), z(a[2]), w(a[3])
 }
 
 //-----------------------------------------------------------------------------
-inline float Vector4::operator[](uint32_t i) const
+inline const float& Vector4::operator[](uint32_t i) const
 {
 	CE_ASSERT(i < 4, "Index must be < 4");