Showing posts with label friend over normal operator overloading. Show all posts
Showing posts with label friend over normal operator overloading. Show all posts

Sunday, May 8, 2022

friend function overloading over normal operator overloading

 /*program to show use of friend function operator overloading over normal

operator overloading using methods
a pro of using friend operator overloading instead of normal is that
we can use it to overload for simple datatypes like class obj and int datatype
which aint possible with normal operator overloading
*/
#include <iostream>
using namespace std;
class A
{
    int num1;

public:
    A() {}
    A(int num1)
    {
        this->num1 = num1;
    }
    friend int operator+(A &, int);
};
int operator+(A &a, int num2)
{
    return a.num1 + num2;
}

int main()
{
    A a(2);
    int num2 = 4;

    cout << a + num2;

    return 0;
}

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts