Q:

For the class you wrote for exercise 7.40 in § 7.5.1 (p. 291), decide whether any of the constructors might use delegation. If so, write the delegating constructor(s) for your class

0

For the class you wrote for exercise 7.40 in § 7.5.1 (p. 291), decide whether any of the constructors might use delegation. If so, write the delegating constructor(s) for your class. If not, look at the list of abstractions and choose one that you think would use a delegating constructor. Write the class definition for that abstraction.

All Answers

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

(a) Book

class Book {
    public:
      //Book() : isbn(""), name(""), author(),
      //    publish_year(0), publisher(""), version(0) {}
      Book() : Book("", "", std::vector<std::string>(), 0, "", 0) {}
      Book(const std::string &i, const std::string &n,
           const std::vector<std::string> &au,
           unsigned y, const std::string &p = "", unsigned v = 1)
          : isbn(i), name(n), author(au),
            publish_year(y), publisher(p), version(v) {}
      Book(std::istream &is) {
        is >> isbn >> name;
        std::string s;
        is >> s;
        author.push_back(s);
        is >> publish_year >> publisher >> version;
      }

    private:
      std::string isbn;
      std::string name;
      std::vector<std::string> author;
      unsigned publish_year;
      std::string publisher;
      unsigned version;
    };

(b) Date

(c) Employee

(d) Vehicle

(e) Object

(f) Tree

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