Person(const string &name)
{
mName=name;
}
Person(string name)
{
mName=name;
}
mName is a private member variable
So I made a class called Person. I'm wondering whats the difference between const string &name and string name. I have tried just putting string &name but it gave me an error message.
I know & is a reference so almost like an address? I'm guessing the const is needed because the reference is a constant? Also, why doesn't just string &name work?
This is the error message that I got
candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const char [4]' to 'const Person' for 1st argument
candidate constructor not viable: no known conversion from 'const char [4]' to 'string &' (aka 'basic_string, allocator > &') for 1st argument Person(string &name)