Skip to main content
added 10 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
  • Lose the private, class members are private by default.

    Lose the private, class members are private by default.

  • setGolf() Instead of returning 1 or 0, you can apply exceptions management here. Also

    setGolf(): Instead of returning 1 or 0, you can apply exceptions management here. Also, you're doing double jobs by *this = Golf(name, hc);. You call a constructor that creates an instance of Golf and then assign that instance to *this when you don't even have an assignment operator defined. Don't worry, a default version is already generated.

    you're doing double jobs by *this = Golf(name, hc);. You call a constructor that creates an instance of Golf and then assign that instance to *this when you don't even have an assignment operator defined. Don't worry, a default version is already generated.

    You can fix that by doing this:

      this->fullname = name;
      this->handicap = hc;
    

You can fix that by doing this;

this->fullname = name;
this->handicap = hc;
  • Lose the private, class members are private by default.
  • setGolf() Instead of returning 1 or 0, you can apply exceptions management here. Also you're doing double jobs by *this = Golf(name, hc);. You call a constructor that creates an instance of Golf and then assign that instance to *this when you don't even have an assignment operator defined. Don't worry, a default version is already generated.

You can fix that by doing this;

this->fullname = name;
this->handicap = hc;
  • Lose the private, class members are private by default.

  • setGolf(): Instead of returning 1 or 0, you can apply exceptions management here. Also, you're doing double jobs by *this = Golf(name, hc);. You call a constructor that creates an instance of Golf and then assign that instance to *this when you don't even have an assignment operator defined. Don't worry, a default version is already generated.

    You can fix that by doing this:

      this->fullname = name;
      this->handicap = hc;
    
Source Link
Olayinka
  • 273
  • 1
  • 10

  • Lose the private, class members are private by default.
  • setGolf() Instead of returning 1 or 0, you can apply exceptions management here. Also you're doing double jobs by *this = Golf(name, hc);. You call a constructor that creates an instance of Golf and then assign that instance to *this when you don't even have an assignment operator defined. Don't worry, a default version is already generated.

You can fix that by doing this;

this->fullname = name;
this->handicap = hc;