Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

operator overloading c++

// Use operator overloading to change the behaviour of division to multiplication for user defined data types

#include <bits/stdc++.h>
using namespace std;

class parent
{
    int x;

public:
    parent(int y)
    {
        this->x = y;
    }

    void operator/(parent p)
    {
        int temp = this->x * p.x;
        cout << temp;
    }
};

int main()
{
    parent obj1(10), obj2(20);
    obj2 / obj1;

    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #operator #overloading
ADD COMMENT
Topic
Name
1+4 =