-1

Possible Duplicate:
Operator overloading

Is it possible you define symbols like '+, -, *, /' for objects in C++? I can't find any docs on it, and it would be useful/exciting to do this!

Community
  • 1
  • 1
ceptno
  • 687
  • 2
  • 6
  • 28

1 Answers1

0

One thing you will have to learn when programming is that subtle distinctions matter. Often they matter a great deal. It behooves you to become familiar with the technical jargon and its precise meaning.

You called those 'symbols'. In C++, symbols are one of several different possible things:

  • Either you are referring to the thing the linker uses to connect parts of your program up. The names of functions and global variables become 'symbols'.
  • Or you are referring to a class of individual characters typically called 'symbols'. This is a very fuzzy set, but generally includes most things you would get by holding down shift and typing all the numbers on a US english keyboard. But as a symbol these are meaningless to C++.

From the context of your question, it's clear that you do not mean either of those two things when referring to the word 'symbol'. You think you're referring the second case I list above. But while it might superficially seem to be the case, it's not. What you are referring to are called 'operators'. Operators are things that tell the compiler that you're trying to operate on a value. They occur as parts of expressions. C++ has a very large number of them compared to most languages.

A symbol can be interpreted by the compiler as an operator. But a symbol is not an operator and an operator is not a symbol. For example && is an operator. But it's also two & symbols. As another example, @ is a symbol, but there is no operator @ in standard C++.

If you search for 'operator overloading', you will get the information you're looking for.

Omnifarious
  • 54,333
  • 19
  • 131
  • 194