469,963 Members | 1,838 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

difference between return &*i and return i;

Hi All,

At some places in code, I see following statements,

const XMLCh* some_func()
{
return &*(*i)->m_Value.begin();
}

Is that any different from following syntax ?

const XMLCh* some_func()
{
return (*i)->m_value.begin();
}

Thanks
Ganesh.
Jul 22 '05 #1
4 1683
Ganesh Gella wrote:
At some places in code, I see following statements,

const XMLCh* some_func()
{
return &*(*i)->m_Value.begin();
}

Is that any different from following syntax ?

const XMLCh* some_func()
{
return (*i)->m_value.begin();
}
...


'i' could easily be different from '&*i' if the '*' operator is
overloaded in 'i'. That appears to be the case in the code above.

--
Best regards,
Andrey Tarasevich
Jul 22 '05 #2
Ganesh Gella wrote:
Hi All,

At some places in code, I see following statements,

const XMLCh* some_func()
{
return &*(*i)->m_Value.begin();
}


If the value returned by begin() has an overload for operator*
(or the result of *begin() has an overload for &), it's not the
same as omitting the &*.

For example if m_Value is list<XMLCh> type, then begin() returns
list<XLMCh>::iterator which is NOT the same as XMLCh*. It does
however have an operator* that reutrns XMLCh& and you can take the
address of that to get the adderss of the XMLCh object in the list.
Jul 22 '05 #3

"Ganesh Gella" <gk******@yahoo.com> wrote in message
news:d3**************************@posting.google.c om...
Hi All,

At some places in code, I see following statements,

const XMLCh* some_func()
{
return &*(*i)->m_Value.begin();
}

Is that any different from following syntax ?

const XMLCh* some_func()
{
return (*i)->m_value.begin();
}

Thanks
Ganesh.


Yes, the return from begin() is (presumably) an iterator, and the return
from &* ... begin() is (presumably) a pointer.

john
Jul 22 '05 #4
gk******@yahoo.com (Ganesh Gella) wrote in message news:<d3**************************@posting.google. com>...
Hi All,

At some places in code, I see following statements,

const XMLCh* some_func()
{
return &*(*i)->m_Value.begin();
}

Is that any different from following syntax ?

const XMLCh* some_func()
{
return (*i)->m_value.begin();
}

Thanks
Ganesh.


outside of operator loading, yes. but with operator overloading it can be anything
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Mattias Campe | last post: by
19 posts views Thread by John Keeling | last post: by
1 post views Thread by learning_C++ | last post: by
4 posts views Thread by Joel | last post: by
3 posts views Thread by gevadas | last post: by
33 posts views Thread by onkar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.