/* constr1.cpp */ #include #include #include using namespace std; class Book { int cost; string author; public: Book(){}; //Default constructor Book(int c, string a); friend ostream& operator<<(ostream& who, Book & what) { who << what.author << " " << what.cost; return who; } }; Book::Book(int c, string a): cost(c), author(a) {} int main () { Book a; // a is with undefined values of cost and author Book b(7, "Tolstoy"); a = b; // assignment is componentwise cout << a << endl; } /* The out put of this program is just: Tolstoy 7 */