DEV Community

Discussion on: Understanding recursions and memory

 
pentacular profile image
pentacular

The explanation is that your thinking is incorrect. :)

In the example x is not a reference, so a is passed by value.
The value of a is assigned to x, which is an independent variable.
So changes to x do not affect a.

There is no 'implicit reference' in C++.

When you change x to be Foo& , a is passed by reference.

This is the difference between pass by value and pass by reference, and class instances are passed by value as usual.

Thread Thread
 
therise3107 profile image
Lalit Yadav

Yeah, I was confused initially about why to use references with the object now it makes much more sense to me. C++ is surely deep :). Thanks for your valuable comments, I will be posting my C++ endeavors as I go on learning new stuff but this time I will be precise with my word selection and topic :)