In C++, i know there are two ways to overload. We can overload it inside (like class a
) or outside (like class b
). But, the question is, is there any difference between these two either in compile time or runtime or not?
class a
{
public:
int x;
a operator+(a p) // operator is overloaded inside class
{
a temp;
temp.x = x;
temp.x = p.x;
return temp;
}
};
class b
{
public:
friend b operator+(b, b);
int x;
};
b operator+(b p1, b p2) // operator is overloaded outside class
{
p1.x += p2.x;
return p1;
}