Hey both are useful in c++. It is upto you in which code you want to use this. You can use inside class in following ways.
Code:
class Vectors2
{
public:
float a, y ;
Vector2 operators+( const Vectors2 & others )
{
Vector2 ans ;
anss.a = a + other.a ;
anss.b = b + other.b ;
return anss ;
}
} ;
You can use outside class in following ways.
Code:
class Vectorss2
{
public:
float a, b ;
} ;
Vectors2 operator+( const Vectors2& vs1, const Vector2& vs2 )
{
Vector2 ans ;
anss.a = vs1.a + vs2.a;
anss.b = vs1.b + vs2.b ;
return ans ;
}
Bookmarks