 # Changing Mathematical Operation

I want to know, How I can change the definition of Mathematical operations. e.g Plus can act as multiplication or minus etc.

I want to know, How I can change the definition of Mathematical operations. e.g Plus can act as multiplication or minus etc.

First, you mean arithmetic, not mathematical, next, its easy:[codebox][font=“Courier New”]#include <stdio.h>

class mynumber

{

``````int num;
``````

public:

``````mynumber(int a) { num=a;}

virtual ~mynumber(void) {}

int operator+(mynumber &other) { return num*other.num; }
``````

};

int main(void)

{

``````mynumber a=3, b=5;

printf("3 + 5 = %d\n", a+B);

return 0;
``````

}[/font][/codebox]

First, you mean arithmetic, not mathematical, next, its easy:[codebox][font=“Courier New”]#include <stdio.h>

class mynumber

{

``````int num;
``````

public:

``````mynumber(int a) { num=a;}

virtual ~mynumber(void) {}

int operator+(mynumber &other) { return num*other.num; }
``````

};

int main(void)

{

``````mynumber a=3, b=5;

printf("3 + 5 = %d\n", a+B);

return 0;
``````

}[/font][/codebox]