-1

For example:

#include <iostream>
using namespace std;

int main(){
int a;
+a;

}

I want the arithmetic plus " + " operator to be overloaded so that if it appears before one identifier ( in this case "a" ) , it will print " Hello ", without another identifer before the " + " operator , basically not like this : "identifierA+identifierB " , but like this " +identifierB " ( in this case "+a") and the result of the program compilation to be " Hello ". How is this possible?

Thanks in advance for help.

zLeon
  • 137
  • 9
  • 11
    The language does not allow overloading existing operators for fundamental types. – juanchopanza Sep 01 '15 at 12:45
  • For example, I have a dynamic pointer and i'm accessing index 2: " *(pointer+1) " , I tried to figure out how there can be an operator such as asterisk before an identifier of some sort, without an identifier before that. – zLeon Sep 01 '15 at 12:55
  • 2
    To overload the unary plus operator for a user defined type, refer to http://stackoverflow.com/questions/5117563/use-of-unary-plus-operator – Sander De Dycker Sep 01 '15 at 13:00

1 Answers1

3

As mentioned in the comments, overloading existing operators for fundamental types is not allowed in C++. You may overload operators for user defined types, but that isn't your question.

therainmaker
  • 4,253
  • 1
  • 22
  • 41