I have a class.
class Books
{
private:
int m_books;
public:
Books(int books=0)
{
m_books = books;
}
Books(const Books &source) //Here is what I don't understand.
{
m_books = source.m_books;
}
};
I can't understand why it has to be Books(const Books &source), and not Books(const Books source).
When you have
Books(const Books &source)
the source is passed by reference. When you have
Books(const Books source)
it would have been passed by value. But to pass by value you are the copy constructor. So to avoid an infinite recursion, the copy constructor must accept a reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With