Given the class definition:

```
class A
public:
//constructors
// other members
private:
int x;
int y;
```
Give declarations of operator functions for each of the following ways to overload
operator + You must state where the declaration goes, whether within the class in the
public or private section or outside the class. The operator + may be overloaded
a) as friend function
b) as member function
c) as non-friend, non-member function


a) To overload operator+ friend function: place the declaration of the operator
function in the class prefixed by the keyword friend.
friend const A operator+(const A& lhs, const A& rhs);
Notice that there are two arguments, at least one of which has class type, as any
stand-alone operator overloading must. The implementation must also be available to
be compiled and linked to the user code.
b) : To overload operator+ as a member function: place the declaration of the operator
function in the public section of the class (if you want it to be available outside the
class)
const A operator+(const A& rhs);
Notice that there is one argument, which has class type, as any operator overloading
must. The implementation must also be available to be compiled and linked to the
user code.
c) To overload as non-friend, non-member function: Write the implementation of the operator function and put the declaration anywhere you plan to use the operator.const A operator+
```
(const A& lhs, const A& rhs);
```

Computer Science & Information Technology

You might also like to view...

Draw diagonal lines on a picture from top left to bottom right using addLine.

This question can potentially be confusing as it suggests that multiple lines need to be drawn, but does not give precise instructions. To simplify, one can assume that they should draw two lines to get from the top left to bottom right, as below:

Computer Science & Information Technology

A(n) ________ uses different widths for different characters

Fill in the blank(s) with correct word

Computer Science & Information Technology

Since diagram 0 is a(n) _____ version of process 0, it shows considerably more detail than a context diagram.

A. contracted B. exploded C. condensed D. extrapolated

Computer Science & Information Technology

Examples of personal computers include all of the following EXCEPT ________

A) gaming systems B) mobile devices C) notebooks D) desktops

Computer Science & Information Technology