operators
You are here :

Sub nodes

Recent changes
Site plan
 
 

You can define new operators in Nosica. Here's the list of operators you can overload :

Operators syntax

Infix operators

Infix operators are operators that applies on the left member of the expression.

 ResultType infix OperatorName(Argument arg) [const] {
 }

Example :

 int infix ~~(const int rhs) const {
 }

Thus, when you write :

 int i = 0;
 int j = 0;
 if (i ~~ j) {
 }

You're in fact writing :

 int i = 0;
 int j = 0;
 if (i.infix ~~(j)) {
 }

Postfix operators

Postfix operators are operators that applies on the right member of the expression.

 ResultType postfix OperatorName(Argument arg) [const] {
 }

Example :

 class Vector {
   Matrix postfix *(const Matrix rhs) const {
   }
 }

Thus, when you write :

 Matrix i;
 Vector j;
 Matrix k = i * j;

You're in fact writing :

 Matrix i;
 Vector j;
 Matrix k = j.postfix *(i);

This is usefull when wanting to extends an existing class without breaking the protection mechanism. Suppose you have defined * infix operators in the Matrix class. Suppose now that you write a Vector class but you don't want to modify the Matrix class to handle multiplication. The answer is handy : simply write a postfix operator.

Prefix operators

There is only 2 prefix operators :

Syntax :

 ResultType prefix OperatorName() const {
 }

Example :

 int prefix -() const {
 }

Thus, when you write :

 int i = 0;
 int j = -i;

You're in fact writing :

 int i = 0;
 int j = i.prefix -();

A notes on instance operators

Operators ~, ~~, and !~ are called instance operators. They are in fact the copy operator and comparison operators.

See this document for a spec on value/instance operators.

In brief : For reference instances :

For primitive instances :

Propulsed by Wiclear