|
here in this constructor :
CommissionEmployee(const string &, const string &,const string &, double=0.0);
why we are using reference & ? whats is the purpose of this ?
|
|
|
|
|
References are used to not have to do copy of the object passed to the constructor, in this case, strings.
If you did not used references, the string would have been copied at least 1 time too many.
Nihil obstat
|
|
|
|
|
References are basically pointers so this of this as an 'address', or a 'reference' to an object.
==============================
Nothing to say.
|
|
|
|
|
The purpose of & in constructor methods is the same it have in any other method: pass arguments by reference (instead of by value).
The usual reason is performance (avoid creating temporaries).
Veni, vidi, vici.
|
|
|
|
|
which is called pass by reference. we can pass arguments in two type
1. pass by value
2. pass by reference
if we use pass by reference same location is passed to functions. no copying is occured. so any changes made is also reflect in original variable. so use const for to provide unexpected changing.
|
|
|
|
|
A constructor is a class member function in C++ and C# that has the same name as the class itself.
The main purpose of the constructor is to initialize all member variables when an object of a said class is created. (Resources acquired such as memory or open files are typically released in the class destructor).
Constructor are automatically invoked when the object is created. Constructor doesn't have any return type, including return voids.
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:39am.
|
|
|
|