what is an operator

hi all,
we all know that c++ has many operators like new , = , << etc

but what essentially is an operator? how does it differ from a normal function?


It is basically a normal function that can be called with a different syntax.
so.. why is it termed operator then?? what makes it special?

In other words, by looking at the syntax (apart from the fact that the name starts with operator) will we be able to know whether a given function is an operator??

Can be override the address-of ( &) operator?
An overloaded operator is a function. It's called operator because it looks like a regular operator at the call point (but it doesn't have to).
Now, regular operators are nothing like functions.
http://en.wikipedia.org/wiki/Operator_%28programming%29
will we be able to write the custom operators??

say if I want to make "<?" as an operator.. will I be able to do so?

for example if i want to achieve the following functionality

1
2
3
std::string SomeString="hi"; 
  SomeString<?"$"
  std::cout << SomeString


desired output : $hi$
No, you can only edit existing operators. Operators are basically functions that handle basic arithmetics with specific types. You can overload them; causing them to support more types, but you cannot create new ones.
The other answer is yes, you can override the address-of operator, however there is
rarely a need to do so, is annoying (see boost::addressof), and often times can end up
breaking code that unwittingly assumes that &obj gives a pointer to the first byte of
memory used for "obj" if "obj" is of class/struct type (and no multiple inheritance used).
@jsmith..
Overloading address of operator would help us a great deal in implementin the garbage collect..

Similarly can we also overload *?
Yes.

You can overload most of the operators in the C++ Language.
The only operators that can't be overloaded are . (dot), sizeof, ::, ?:, and, according to the FAQ, .* (whatever that is).
Topic archived. No new replies allowed.