Q:

Provide operations in your Person class to return the name and address. Should these functions be const? Explain your choice

0

Provide operations in your Person class to return the name and address. Should these functions be const? Explain your choice.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <string>

struct Person {
  std::string getName() const { return name; }
  std::string getAddress() const { return address; }

  std::string name;
  std::string address;
};

// The member function `getName` and `getAddress` should be `const`, because
// they don't change the object.

int main() {
  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now