Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Reference u jeziku C++

[es] :: C/C++ programiranje :: C/C++ za početnike :: Reference u jeziku C++

[ Pregleda: 3828 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

vlaga
Valentino Kolev

Član broj: 85208
Poruke: 25
*.SMIN.panline.net.



Profil

icon Reference u jeziku C++25.07.2006. u 15:31 - pre 216 meseci
Zanima me sta su reference, zasto su uvedene u c++ i kakva je razlika izmedju reference i pointera?
Dobro bi doslo objasnjenje na primeru, kao i literatura(link) u kojoj je to objasnjeno.
Hvala
 
Odgovor na temu

android~paranoid

Član broj: 81947
Poruke: 211
*.041net.co.yu.



Profil

icon Re: Reference u jeziku C++25.07.2006. u 22:48 - pre 216 meseci
Referenca (alijas, upucivac...) je slicna pokazivacu, to je kao druga vrsta identifikatora,
stim da se stalno vezuje za taj deo memorije.

Uvedena je u C++ zbog lakseg koriscenja u odnosu na pointere,
pri prenosu parametara u f-ji po adresi(kad treba da vrate vrednosti)
lakse je ne dereferencirati stalno promenjivu (*p).

Mislim, šta reći !
 
Odgovor na temu

vlaga
Valentino Kolev

Član broj: 85208
Poruke: 25
*.SMIN.panline.net.



Profil

icon Re: Reference u jeziku C++26.07.2006. u 13:32 - pre 216 meseci
Sad mi je jasno teoretski, ali bih voleo da vidim neki primer.
Hvala
 
Odgovor na temu

darkon
Darko Novakovic
Istrazivac, IMP
Beograd

Član broj: 13647
Poruke: 166
*.rcub.bg.ac.yu.

Jabber: darkon@elitesecurity.org


+1 Profil

icon Re: Reference u jeziku C++26.07.2006. u 13:42 - pre 216 meseci
Evo nekoliko linkova:

http://www.embedded.com/story/OEG20010311S0024
http://www.relisoft.com/book/lang/pointer/1ptrref.html
http://www.parashift.com/c++-faq-lite/references.html
http://amitp.blogspot.com/2004/04/c-references-vs-pointers.html

Citat:
Use references when you can, and pointers when you have to.

References are usually preferred over pointers whenever you don't need "reseating". This usually means that references are most useful in a class's public interface. References typically appear on the skin of an object, and pointers on the inside.

The exception to the above is where a function's parameter or return value needs a "sentinel" reference — a reference that does not refer to an object. This is usually best done by returning/taking a pointer, and giving the NULL pointer this special significance (references should always alias objects, not a dereferenced NULL pointer).

Note: Old line C programmers sometimes don't like references since they provide reference semantics that isn't explicit in the caller's code. After some C++ experience, however, one quickly realizes this is a form of information hiding, which is an asset rather than a liability. E.g., programmers should write code in the language of the problem rather than the language of the machine.

"Verovatno da preko nje mnoge sile kontrolišu mnogo šta..." - GANDOR
"Kada bi ljudski mozak bio tako jednostavan da bismo mogli da ga shvatimo, onda bismo mi bili toliko glupi da ga ipak ne bismo mogli shvatiti."
 
Odgovor na temu

vlaga
Valentino Kolev

Član broj: 85208
Poruke: 25
*.SMIN.panline.net.



Profil

icon Re: Reference u jeziku C++27.07.2006. u 13:58 - pre 216 meseci
Hvala, linkovi sadrze sve sto mi treba.
 
Odgovor na temu

[es] :: C/C++ programiranje :: C/C++ za početnike :: Reference u jeziku C++

[ Pregleda: 3828 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.