cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Regarding references
Regarding references
Sep 24, 2014 at 5:58pm UTC
vishnu123
(22)
it is said that references once intialized to one object cannot refer to another object
i wrote a code like
class A
{
// some data members and functions
}
int main()
{
A a,b;
A &ref=a;
ref=b; //but this works fine
}
please explain me the above statement with code and also tell me why it cant refer to another objects
thanks in advance
Last edited on
Sep 24, 2014 at 6:04pm UTC
Sep 24, 2014 at 6:09pm UTC
MiiNiPaa
(8886)
ref=b;
//but this works fine
here you are not rebinding the reference, you are changing the object, reference points to.
This line and (
a=b;
) are absolutely equivalent.
Last edited on
Sep 24, 2014 at 6:10pm UTC
Topic archived. No new replies allowed.