The prototype of get should be constchar* get() const so you can call it from const objects ( as you are doing in the copy constructor.
The first const means that the C string returned by get can't be modified externally, the second means that the function itself doesn't modify the object
you said that we need these const's so that we can call this function from const object but if i remove const from the copy construction parameter then it should not give a error..!
A copy constructor must copy the contents of an existing object ( without modifying it ) into the new object
The alternatives are:
- passing by value: It will cause an infinite copy loop since the argument to the constructor itself must be copied to get it's value
- passing by reference: It may modify the argument and it can't take rvalues or const objects
- passing by const reference: Will work