-
Need help.
In a program, it has
class simplecat
{
public:
simplecat();
simplecat(simplecat&);
~simplecat();
....
....
etc...
What does this offer, why is the ampersand (&) by the word cat, and not simple.
This program is a part of samspublishing 21 days.
I don't understand this
please help
thanks.
-
because simplecat(simplecat) would be an infinite loop. The function we are talking about there is called the copy constructor. It is called whenever a copy of an object needs to be made. If we pass a simplecat to it by value then we would have to copy it hence calling the copy constructor. To get around this and also for reasons of efficiency we pass the object by reference or better still by const reference. The ampersand denotes that this is a reference. simplecat& is reference to simplecat.