I am using an example from Sams Teach Yourself C++ In One Hour a day. The instructor states that passing sayHello by value to the function UseMyString() around line 68 results in the copy constructor being called. I do not understand why. Could someone explain? Is it because sayHello is a function of MyString type? Thanks
Thanks for the reply. Your question is a good one for me. I realize I am not clear on that also. Does str get its value when str.GetLength() is called or earlier?
Yes, on line 69 a function is called with an argument. That argument is used to initialize the parameter str. It is like you had written: MyString str( sayHello );
By value parameters are copies of the values that the function is called with.