so i was previously on Old Intermediate Lessons number 6 i think i kinda just got lost because of how long the lessons were at that time. so I went on my own code path for a while.
i am now sort of creating my own 2D Game engine( or framework, which ever you prefer to call it) with the goals of being platform independent.
so i picked ups SDL2(simple direct media library) and began learning that API and have been slowly chipping away progress when i have the time.
so I'm at the point where I am creating lots of geometric math things such as Vectors and shapes, such as rectangles and circles.
what i have that is working great thus far
&operator +=
&operator -=
&operator *=
&operator /'=
now when trying to start to work on collision detection I felt like i could make my life a lot easier by
creating a less than or equal to (<=) and greater than or equal to (>=)
never had to overload these operators before so i look it up and cppreference recomends doing it like
Code: Select all
inline bool operator< (const X& lhs, const X& rhs){ /* do actual comparison */ }
inline bool operator> (const X& lhs, const X& rhs){ return rhs < lhs; }
inline bool operator<=(const X& lhs, const X& rhs){ return !(lhs > rhs); }
inline bool operator>=(const X& lhs, const X& rhs){ return !(lhs < rhs); }
it might be because it is inside of a 2dVector class so it assumes the left hand side is a &this
so after fiddling with it based off of compile errors my code now looks like this with no errors.
Code: Select all
bool Vec2df::operator >=(Vec2df rhs){
bool check1 = false;
bool check2 = false;
if(x >= rhs.x){check1 = true;}
if(y >= rhs.y){check2 = true;}
if(check1 ==true)
{
if(check2 == true)
{
return true;
}else{return false;}
}
}
so to wrap this up and get to the point.
will this bite me in the ass later, since im doing it differently than the recommended way. it seems in my minor tests its working fine.
is there a better way you might recommend doing this?
i just need a outsiders perspective because after staring at code for too long my brain has gone a little numb.