Open
Description
The exercise requests the following:
bool valid() const: Returns true if the constructor could successfully do its work. If not, it returns false, in which case the return values of the other member functions are all invalid.
What would be the correct way to do this? I have it initialize to false and set it to true at the end now:
User::User()
:
d_valid(false)
{
d_userId = geteuid(); // identify current user
passwd *pw = getpwuid(d_userId); // passwd file for current user
d_name = string(pw->pw_name);
d_groupId = pw->pw_gid;
d_homeDir = string(pw->pw_dir);
d_realName = string(pw->pw_name);
d_shell = string(pw->pw_shell);
d_valid = true;
}
But to have all values end up invalid I would need to more code, which seems convoluted.
Metadata
Metadata
Assignees
Labels
No labels