Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Advanced C programming in lcc-win32

visual c en


Advanced C programming in lcc-win32

Operator overloading

When you write:

int a=6,b=8;

int c = a+b;

you are actually calling a specific intrinsic routine of the compiler to perform the addition of two integers. Conceptually, it is like if you we 545b11f re doing:



int a=6,b=8;

int c = operator+(a,b);

This "operator+" function is inlined by the compiler. The compiler knows about this operation (and several others), and generates the necessary assembly instructions to perform it at run time.

Lcc-win32 allows you to define functions written by you, to take the place of the built-in operators. For instance you can define a structure complex, to store complex numbers. Lcc-win32 allows you to write:

COMPLEX operator+(COMPLEX A, COMPLEX B)

This means that whenever the compiler sees "a+b" and "a" is a COMPLEX and "b" is a COMPLEX, it will generate a call to the previously defined overloaded operator, instead of complaining about a "syntax error".

This is called in "tech-speak" operator overloading. There are several rules for writing those functions and using this feature. All of them explained in-depth in the user's manual. This short notice is just a pointer, to show you what is possible.

The implementation of this feature is compatible with the C++ language that offers a similar facility.

References

References are a special kind of pointers that are always dereferenced when used. When you declare a reference, you must declare immediately the object they point to. There are no invalid references since they can't be assigned. Once a reference is declared and initialized, you can't reassign them to another object.

They are safer pointers than normal pointers, since they are guaranteed correct, unless the object they point to is destroyed, of course. References are initialized with the construct:

int a;

int &pa = a;

The "pa" variable is a reference to an integer (an "int &"), and it is immediately initialized to point to the integer "a". Note that you do not have to take the address of "a", but just put its name. The compiler takes the address.

Again, here is a short pointer only. A complete description is found in the user manual.


Document Info


Accesari: 957
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )