1. 《inside the cpp object model》读书笔记

by huangyi

1.1. Object Lessons

   1     Book book;
   2     Library_materials thing1 = book;//拷贝语义
   3     thing1.check_in();//Library_materials::check_in
   4     Library_materials &thing2 = book;//创建别名
   5     thing2.check_in();//Book::check_in
   6 

   1 TheClass aClass;

   1         // class Book : public Library_materials { ...}; 
   2         Book book; 
   3 
   4         // Oops: thing1 is not a Book! 
   5         // Rather, book is ``sliced'' ?
   6         // thing1 remains a Library_materials 
   7         thing1 = book; 
   8 
   9         // Oops: invokes 
  10         // Library_materials::check_in() 
  11         thing1.check_in(); 
  12 
  13         // OK: thing2 now references book 
  14         Library_materials &thing2 = book; 
  15 
  16         // OK: invokes Book::check_in() 
  17         thing2.check_in();

1.2. The Semantics of Constructors

1.2.1. Default Constructor Construction

huangyi/2006-06-05.

huangyi/2006-06-05 (last edited 2009-12-25 07:14:15 by localhost)