Overloading Vector2D Assignment Operators

preview_player
Показать описание
Jamie King showing how to overload the += operator. Without thinking about it, I overloaded the assignment and copy constructors as well--which I should not have. I talk about why and repent of this sin in video 48.
Рекомендации по теме
Комментарии
Автор

You could also define in the EngineTester Main.cpp which tests to run with the help of a filter.
I did it like this

::testing::GTEST_FLAG(filter) = "Vector2D*";
RUN_ALL_TESTS();

I love your videos Jamie :) Keep up the good work

bushuo
Автор

This is a fantastic series of videos - but I think this one could have merited a little more discussion. There are significant differences in how the operators are defined in relation to the previous set - the operators require an instance. On my first attempt, Visual C++ became somewhat upset about the inline file and it was difficult to diagnose the root causes of the errors.

Spodgy
Автор

Intristing thing.. i thought that i could use your trick from before so i tried to implement assignement operator like this

Vec2& Vec2::operator=(const Vec2& v)
{
// x = v.x;
// y = v.y;
return Vec2(v);
}
and it didn t work but if i left those two things uncomented it assigned just fine.. copy constructor is made same way as yours.. WHY IS THAT???

miroslavkovac
welcome to shbcf.ru