I am reading a book on C++ by DEITEL. There is a code snippet in chapter 10 of deitel regarding "COMPOSITION".
There is a Date and employee class. For composition, an object of a class (Date) can be used a member object in employee class. What I dont understand is what advantage does passing a constant reference of the date object to constructor of employee provides. I do know that when passing by reference you can modify the the original value because compiler does not create a copy of the value as opposed to "pass-by-value".
Thanks in advance.
I can also past the code snippet for clarification of my question.
Passing a const variable just means the variable being passed cannot be changed or altered. It is good practice to pass as a constant variable so your code doesn't change or alter the variable by accident in case you change the function later in time. If you pass. If you pass a variable by value you use more memory in order to create another memory location to hold the temporary variable being used by the function.
Passing by const refernce you access the original variable but cannot change the value saving run time and memory
So basically, when we are passing an object to a function, a better practice is that we should always pass the object by reference. Even though, we can pass the object directly as I have tried ( the compiler wont give any errors).
Basically there are 3 ways to pass by copy , reference , or by pointer. The first (copy) method creates a temporary copy somewhere in the stack memory and uses it until the function ends so each time you call this function you are calling a constructor and destructor of the object. If you pass by the later two you are passing the object itself via memory address then using it in the local scope and only calls the construct and destructor where you have created the object.
Ok, this is a different question and I don't know if i should create a separate thread for it or not, but i am just writing this question over here.
A good software engineering practice is to separate implementation details with the interface and also to hide the private information in the interface. For this reason, a proxy class is created. My question is when i am using a proxy class, what files I will be giving to the client of the code?