Possible Duplicate:
Is it better in C++ to pass by value or pass by constant reference?
see these 2 program.
bool isShorter(const string s1, const string s2);
int main()
{
string s1 = "abc";
string s2 = "abcd";
cout << isShorter(s1,s2);
}
bool isShorter(const string s1, const string s2)
{
return s1.size() < s2.size();
}
and
bool isShorter(const string &s1, const string &s2);
int main()
{
string s1 = "abc";
string s2 = "abcd";
cout << isShorter(s1,s2);
}
bool isShorter(const string &s1, const string &s2)
{
return s1.size() < s2.size();
}
Why second one is better?