thnx a lot

On Wed, Oct 10, 2012 at 9:27 AM, Saurabh Kumar <srbh.ku...@gmail.com> wrote:

> >>> but i have read that reference is a const pointer
> That is NOT true. A reference is not a const pointer. Period.
> It's only because they 'point' to an object and cannot be changed to
> 'point' to some other object, people say its' a const pointer which is not
> entirely true. References never 'point' to anything.
> Reference is an *abstract concept*. an* alias *or a* 'different name for
> same object'*.
> A compiler may choose to implement it using a pointer or may not, it
> depends on compiler.
>
> >> What is size of reference.
> Had they been simple const pointers you'd get 4-Bytes(on 32 bit
> architecture) or 8-Bytes (on 64 bit architectures). But what you'll
> actually get is *size of the object* itself.
> In fact ISO C++ standard itself says that whether or not a reference
> requires a storage is unspecified. i.e. It is compiler dependent how they
> are implemented internally.
> But Internal implementation mechanisms will never alter the visible
> behavior which is mandated by the Standard so, what sizeof(reference) will
> return will always be size of Object itself.
>
> >>what is return by reference??
> It is nothing different than a reference initialization for all practical
> purposes.
>
> Let func be a function of class Circle:
> *Circle& Func(double r){*
> * //Do something...*
> * return *this;*
> *}*
> *
> *
> and, you call this function like: (This is how your *return by 
> reference*get's consumed.
> *Circle &ref = Func(7.5);* // { As we know reference initialization is
> done with object and not by pointers to those objects so, *rvalue should
> be an Object* of class Circle NOT a pointer.}
>
> >>>does it mean some pointer returned or it mean whole object returned??
> The whole object is to be passed to the *'reference initialization'
> mechanism* of the compiler. So you've to return an object itself(that's
> why make sure you are returning some object that will persist after the
> function call and not an object which will get destroyed with stack
> unwinding of Func call.
>
>
> Please don't say references are nothing but const pointers, just throw
> that notion out of your head.
> Points to gather:
> *1. On the surface you can assume: References are just 'different names
> for same object'. *
> *2. While initializing them I need to pass the whole Object to the
> reference initialization mechanism(which btw, is compiler dependent).*
> *3. Sizeof(reference) is always the sizeof Object itself. (mandated by
> C++ standard)*
> *4. Do references require extra storage? Maybe or maybe not. Read your
> compiler docs.*
>
> On 10 October 2012 02:30, rahul sharma <rahul23111...@gmail.com> wrote:
>
>> Clear some more questiosn
>>
>> 1. What is size of reference.????
>>
>> 2.what is return by reference???it means we return the object itself
>> instead of copying it into temp. variable and then return as in c. in c++
>> we return original variable itself..then when we return by reference wat
>> does that mean,,,does it mean some pointer returned or it mean whole object
>> returned??
>>
>>
>> On Wed, Oct 10, 2012 at 2:23 AM, rahul sharma <rahul23111...@gmail.com>wrote:
>>
>>> Got confused....cant get it......:([?]
>>>
>>>
>>> On Wed, Oct 10, 2012 at 1:00 AM, Prem Krishna Chettri <
>>> hprem...@gmail.com> wrote:
>>>
>>>> Well Lemme try few more hand here..
>>>>
>>>> Basics First Guys :-
>>>>
>>>>               this :-  is a hidden pointer to a class (Agree ?). So
>>>> whats so special about it.. Answer is its compaction when the object of the
>>>> class is being created. Why? Here it goes. As object memory allocation (I
>>>> hope everyone knows) have memory structure such that the first parameter
>>>> always starts with arg[1]. so why not arg[0] as array always indexes with
>>>> "0"? The Answer is here.. Coz every time the object of a class is generated
>>>> the Zeroth index is alwayz occupied by this "*this*" pointer. So if do
>>>> you follow me up to here properly that you know the significance of this
>>>> now.. Coz its object refference lies to the value of offset 0 to the base
>>>> address of the class's object, giving the flexibility to express any member
>>>> of the class by directly accessing via its base address and this also
>>>> explains why this has to be a pointer and not a normal member variable.
>>>>
>>>>                Now here comes the other part of question.why we need *
>>>> " ** *this"*  where *"this"* should give the base address of the
>>>> object of the class we wanna refer. The Answer is partly "YES" coz as we
>>>> discuss "*this" *knows almost everything about the class or rather an
>>>> object of a class within a class scope  but here is the catch we are
>>>> telling someone to get a bowl of rice from my private house. So how will he
>>>> be able to get it? Until I tell him my house structure, which in
>>>> programming language like C++ is reference.
>>>>
>>>>            I am saying sir, I have created a house (object) and here is
>>>> the layout (referring to what I have created) so inorder to tell him about
>>>> my layout I have to generate the return value which is NOT the house
>>>> (object) but the reference to the house ( "pointer" pointing to what I have
>>>> created ).
>>>>
>>>>          Now I am almost done here.. So Why  " ** this *" and not "*
>>>> this*" is coz  "*this"*  gives the object directly to the the party
>>>> who is calling me and the reference means a copy not the object itself
>>>> whereas " ** this *"  is presenting you what you were looking for.
>>>>
>>>>       I hope now people are clear about all the above aspects.. I mean
>>>> the very last question about returns full object or wat?? if you get all
>>>> this.. U got all this.. :)
>>>>
>>>> Ciao,
>>>> Prem
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Oct 10, 2012 at 12:23 AM, rahul sharma <rahul23111...@gmail.com
>>>> > wrote:
>>>>
>>>>> @saurabh....if i look from the way that i need to return a
>>>>> referencei.e. i mean object...i will ryt *this for this..........i knew
>>>>> this............but i have read that reference is a const pointer ....so 
>>>>> if
>>>>> i look from this prespective then do i need to return
>>>>> pointer(this)..............
>>>>> int * fun()//return pointer to int
>>>>>
>>>>> then what does return by reference mean if i return ( *this)..then
>>>>> what actually returns...........full object???or pointer to object...mix
>>>>> questions ...plz clear me..
>>>>>
>>>>>
>>>>> On Tue, Oct 9, 2012 at 11:26 PM, Saurabh Kumar 
>>>>> <srbh.ku...@gmail.com>wrote:
>>>>>
>>>>>> >> as we know reference is a const pointer
>>>>>> That is Not quite true.
>>>>>>
>>>>>> >> our aim is ony to return pointer to circle
>>>>>> No. our aim is to return a reference to circle.
>>>>>>
>>>>>> When you've to define a reference you do something like: *Circle &ref
>>>>>> = c;*
>>>>>> you *don't* do: *Circle &ref = &c;* Right ?
>>>>>>
>>>>>> Same is the case here, at the receiving end where the call was
>>>>>> initiated a reference is waiting there to be initialized, so you pass the
>>>>>> Object (*this) itself and NOT the pointer (this).
>>>>>> [Also remember if you've a complex object, no copy constructors etc.
>>>>>> are called when an object is sent for *reference receiving,* so no
>>>>>> need of worries there.]
>>>>>>
>>>>>> References are not quite exactly same as pointers, they were
>>>>>> introduced much later as a wrapper to pointers but there are some subtle
>>>>>> differences between them when it comes to writing code, behaviorally, yes
>>>>>> they are more or less the same.
>>>>>>
>>>>>> On 9 October 2012 22:54, SAMM <somnath.nit...@gmail.com> wrote:
>>>>>>
>>>>>>> This used for the following situation when   a=b=c=d  (Consider then
>>>>>>> as the  objects of a particular class say X ).
>>>>>>>
>>>>>>>
>>>>>>>  --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Algorithm Geeks" group.
>>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>>
>>>>>>
>>>>>>  --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Algorithm Geeks" group.
>>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>>
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

<<322.png>>

Reply via email to