[openbeos] Re: Pointer or reference?

  • From: burton666@xxxxxxxxxxx
  • To: openbeos@xxxxxxxxxxxxx
  • Date: 29 Mar 2004 07:39:08 -0000

>>Passing a reference to a function is not any different from passing a pointer 
>> 
>to it. In both cases the address of the referenced object must be passed.
>
>The following two functions, for instance, are compiled to exactly the same  
>executable code:
>
>extern "C"
>void
>add_one(int& var)
>{
>       var++;
>}
>
>extern "C"
>void
>add_one(int* var)
>{
>       (*var)++;
>}
>

Exactly.
If I may add something to this perfect explanation, StrouStroup added 
references for this very reason. To make the code look nicer when using 
operators like +, ++, -, --, etc.



Stefano Ceccherini aka Jack Burton
-----------------------------------------------------------
Spazio ILLIMITATO per la tua Email, Scanner Antivirus,
Antispam, Backup e POP3. Prova la nuova Email di superEva:
http://webmail.supereva.it/
-----------------------------------------------------------


Other related posts: