This is derived from Herb Sutter's gotw3 (http://www.gotw.ca/gotw/003.htm).
With the following class and FindAddr function...
using std::string;
using std::list;
class Employee
{
public:
Employee(const string& n, const string& a) : name(n), addr(a) { }
string name;
string addr;
};
string FindAddr(const list<Employee>& l, const string& name)
{
string addr;
list<Employee>::const_iterator i = find(l.begin(), l.end(), name);
if (i != l.end()) {
addr = (*i).addr;
}
return addr;
}
I get a compile error because the Employee class has no conversion to string. I can see that such a conversion is not necessarily sensible, but for the purpose of the exercise, I added a naive conversion:
string::string(const Employee& e)
{
return e.name;
}
This gives me an error:
gotw3.cc:17:9: error: C++ requires a type specifier for all declarations
string::string(const Employee& e)
~~~~~~ ^
What am I doing wrong?