Re: Problem of Pass by Reference in C++

From: lallous (lallous_at_lgwm.org)
Date: 12/15/03


Date: Mon, 15 Dec 2003 12:52:00 +0200


"alan" <cheung_yuklun@i-cable.com> wrote in message
news:7bd5ab13.0312150130.1759ee8e@posting.google.com...
> Hi All,
>
> I have a problem on C++ pass by reference concept.
>
> I saw some funcions which is :
>
> e.g.
> int& func(int &a)
> {
> ....
> ..
> }
>
> I understand the use of "int &a",
> but I would like to know what is the use of "int&" ? and how to use it?
> any examples?
>
> Please help.
> Best regards,
> Alan

Hello,

int t;
int &fnc()
{
  return t;
}

This will return a reference to 't'

Usually the returning by reference is use in classes and to enable
cascading.

--
Elias


Relevant Pages

  • Re: [PATCH] Make futex waiters take an mm or inode reference
    ... Make futex waiters take an mm or inode reference ... Rusty Russell wrote: ... +static inline void drop_key_refs ... -static int futex_wake ...
    (Linux-Kernel)
  • Re: dynamic type checking - a pauline conversion?
    ... it depends on the type of reference to the object. ... In Smalltalk the reference doesn't have a type but the instance does ... and C++ can not guarantee type correctness at compile ...
    (comp.object)
  • Re: Simplicity
    ... > ByRef (by reference) ... > Dim k as Zone ... property int Value; ... Microsoft C/C++ Optimizing Compiler Version 14.00.40809 ...
    (comp.lang.cpp)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Assigning to references
    ... a reference ... behaves exactly like the object it refers to (it is an "alias" for that ... int a = 1; ... Bear in mind that, unlike a reference, a pointer will not extend the ...
    (comp.lang.cpp)