Is it possible to overload operators in class as a macro but not making it a function?
class myInt {
int value;
public:
myInt(int what) {
value = what;
}
inline static friend myInt operator+(myInt& firstInt, myInt& secondInt);
};
inline static myInt operator+(myInt& firstInt, myInt& secondInt)
{
myInt tempMyInt = firstInt.value + secondInt.value; \\want it as macro
return tempMyInt;
}
Above code defines class. I marked that code inside operator overloading,
I would like to be a macro without calling function and without passing arguments.
I ADDED inline static statement BUT IT FAILS to incorporate code into below statements rather than
executing call to function.
myInt myInt1 = 9;
myInt myInt2 = 7;
myInt myInt3 = myInt1+ myInt2;
Above code implements int numbers as class so I can define custom methods.
But normally ints would be adding in single assembler instruction.
After wraping int into class then arguments are passed on stack and function
is called. Those are more than single adding instruction.
I wonder if it would be possible to make operator overloading as macro so
it would only substitute code from inside function so there it would be no
calling overloading function but simple code adding two number.
WHAT IS WRONG WITH ABOVE inline static STATEMENT ?
so
Microsoft C++ fails to execute code inline but continues to call
overloaded function
c++ is still calling overloading operator.
What is wrong?