Sunday, August 5, 2007

c++ review in a blast (core) - three


//117. never use memcpy in c++
//118. every object has a copy constructor
//119. we have to delete objects we currently own before we can create new ones
//120. auto_ptr, release()
//121. exception handling - destructors are guaranteed to be called
//122. auto_ptr takes care of deleting the object it points to, and the object it previously points to
//123. it doesn't however create a new object to point to, we're the one to do that
//124. the exception to the rule on passing ownership - auto_ptr's assignment operator
// passes ownership from one object to the other
//125. make sure assignment happens or none of it - we needed temporary variables
//126. another beauty of auto_ptr is in its documenatry value -
/// if a pointer is declared an auto_ptr, we know its an owning pointer.
// all normal pointers can then be just aliasing pointers
//127. only, its not all portable - check with your compiler
//128. access controls in c++ is a class-by-class basis and not object-by-object basis
//129. any instance of a class can access private members of any other instances of the same class
//130. delete operator in c++ automatically performs NULL check for you,
// so its okay to delete a null pointer.
//131. note: null pointer is different from a dangling pointer (pointer whose object has been deleted)
//132. every object in a well-designed c++ system has a default constructor, a copy constructor and
// an assignment operator
//133. operator= isn't virtual
//134. watch out for 'slicing' in c++
//135. you should always pay attention whether a class is polymorphic or monomorphic
//136. polymorphism imposes special restrictions on what you can do with your objects,
// and the compiler doesn't enforce this restrictions
//137. if you need to copy an object polymorphically, you have to do it yourself
//138. the typical way to this do is to define a virtual function called 'clone()'
// and have every class that inherits 'clone()' override it to call its own copy constructor
//139. reference counting - expense in copying, clear ownership semantic
//140. each object keeps track of how many other objects are pointing to it
//141. counted pointer
//142. counted pointer notifies the object when it no longer refers to it
//143. nobody delete the counted object, it deletes itself - when no one left is pointing to it