S
sarathy
Hi all,
I just wanted to know if it is possible to overload the
original meaning of operators. I read that it is not possible to
change the operator precedence by using operator overloading. Other
than that i think that the operator functionality can be overloaded.
But in the following code, the operator + has been overloaded on type
int. But it does'nt seem to work as the operator fn was not invoked.
In the following code,
# include <iostream>
using namespace std;
namespace blackbox
{
class A
{
public:
int a;
int operator *(int a);
};
int A:
perator * (int b)
{
return a+b;
}
}
int main()
{
using namespace blackbox;
int a=10;
int b=20;
int c=a*b;
cout << c << endl;
return 0;
}
OUTPUT:
---------------
200
Thanks and regards,
Sarathy
I just wanted to know if it is possible to overload the
original meaning of operators. I read that it is not possible to
change the operator precedence by using operator overloading. Other
than that i think that the operator functionality can be overloaded.
But in the following code, the operator + has been overloaded on type
int. But it does'nt seem to work as the operator fn was not invoked.
In the following code,
# include <iostream>
using namespace std;
namespace blackbox
{
class A
{
public:
int a;
int operator *(int a);
};
int A:
{
return a+b;
}
}
int main()
{
using namespace blackbox;
int a=10;
int b=20;
int c=a*b;
cout << c << endl;
return 0;
}
OUTPUT:
---------------
200
Thanks and regards,
Sarathy