Saturday, August 25, 2007

C++ Training at NEC, April 2000

This is the book we used in C++
during our training at NEC, back April 2000.

Bruce Eckel - Part 2

1. Exception Handling
2. Defensive programming
3. Strings in depth
4. Iostream
5. Templates in depth
6. Generic algorithms
7. Generic containers
8. Runtime type identification
9. Multiple inheritance
10. Design patterns
11. Concurrency

Bruce Eckel - Part 1

1. Introduction to Objects
2. Making & Using Objects
3. The C in C++
4. Data Abstraction
5. Hiding the Implementation
6. Initialization & Cleanup
7. Function Overloading & Default Arguments
8. Constants
9. Inline Functions
10. Name Control
11. References & the Copy-Constructor
12. Operator Overloading
13. Dynamic Object Creation
14. Inheritance & Composition
15. Polymorphism & Virtual Functions
16. Introduction to Templates

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

Saturday, August 4, 2007

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


//50. value operator
//51. overloading assignment operator, operator=
//52. compiler implicitly creates a copy assignment operator for a class if you do not define one
//53. it overrides that definition of that of the base class
//54. assignment operator code
//55. copy assignment operator as virtual
//56. compiler choses the type of the pointer
//57. compiler choses the type of the object the pointer is pointing to
//58. copy constructor
//59. A&, const A&, volatile A&, const volatile A&
//59. if you did not declare one, compiler implicitly declares one for you
//60. implicitly defined copy constructor - A::A(A&) or A::A(const A&)
//61. copy constructor copies an existing object to a non-existing object,
// which you are going to create. assignment operator can happen between existing objects
//62. copy constructor is creating new a new object.
// the assignment operator has to deal with the existing data in the object.
// for a simple class, the work done may be the same, but for more complex
// classes,especially with pointers to other objects, there is a need to do more.
// this is related to the deep and shallow copy issue, ownership, is-a-part relationship.
//63. c++ is more strongly typed than c. c allows void*
//64. reference is like a const pointer that is automatically dereferenced
//65. a reference must be initialized when it is created, pointers can be later
//66. once a reference is initialized to an object, it cannot be changed to refer
// to another object - pointers can be anytime
//67. you cannot have null references. you must always be able to assume that
// a reference is connected to a legitimate piece of storage.
//68. member scope
//69. find the fun - then just do it - when you feel enjoying it. side note :)
//70. i want a high energy, adrenaline-rush environment - just extracts the best in one
//71. keep it light and simple, and be kind - no rules, all learn together
//72. const ref - function will not modify
//73. pointer references
//74. argument passing guideline
//75. ideal default habit - pass by const reference
//76. it isn't just about performance early, more at stake
//77. pass by value requires constructor and destructor calls
//78. if you are not going to modify the argument, passing by const reference only
// needs an address pushed on the stack
//79. pass by value only when you wanted to do something bizarre :) to an object
// and the caller is not expecting it, make your own copy then
//80. X(X&) / "X of X ref" - copy constructor
//81. do not aim for perfection, aim for liquidity
//82. this constructor is essential to control passing and returning of user-defined types
// by value during function calls.
//83. it's so important, in fact, that the compiler will automatically synthesize a
// copy constructor if you don't provide one yourself.
//84. understand the need for copy constructor
//85. delete - delete objects
//86. delete[] - delete array
//87. delete operator destroys the object created with new by deallocating the
// memory associated with the object
//88. dynamic memory allocation, deallocation
//89. pointer will be copied but memory it points to will not
//90. original object and copied object points to same object in memory, not one's intention
//91. default copy constructor and assignment operator are shallow copies
//92. to make a deep copy, you must write a copy constructor and overload operator=
//93. deep copy is needed if an object has pointers to dynamically allocated memory
// and that memory needs to be copied when the original object is copied
//94. the class generally needs destructor to delete the dynamically allocated memory,
// copy constructor and overloaded assignment operator
//95. copy constructor is a constructor - creates new object from garbage
//96. assignment operator - copies state of an existing object to another existing object
//97. if you don't want a class to be copied, make an empty cc and ao and make them
// private or protected
//98. compiler isn't guaranteed to create versions of these classes that do exactly
// what you want them to do
//99. assignment operator has to take into account the current state of the object
// when copying the other object's state into it
//100. the current state does matter, and assignment operator is more complicated
//101. you have to do your own memory management
//102. every 'new' that happens during program execution should be balanced
// by one and only one 'delete'
//103. you don't want objects you've created to clutter in memory after you're done with them
//104. you don't want to delete an object more than once, and
//105. you don't to access an object after you have deleted it
//106. double deleting will corrupt the memory manager free list, leading to crushes down
// the road
//107. protocol for managing memory
//108. example protocol: for every object in the runtime environment,
// there is only one and only one pointer to it through which the object can be deleted.
// this pointer is an "owning pointer", and the object or function containing that pointer
// is the object's "owner".
// all other pointers to the object are called "aliasing pointers."
// the owner of the object is expected to delete the object; objects with aliasing
// pointers don't
//109. dangling pointer - a pointer pointing to a deleted object in memory
//110. how about "transmitting of ownership" / return value is an owning pointer -
// passes ownership to the caller
//111. at other times, a function returns a pointer to an object but intends that the
// caller merely use it for a short time to perform some operation.
// ownership is not transferred; the return pointer is an "aliasing pointer"
//112. when you have functions that return pointers or have pointer parameters,
// you must make it explicit whether the function transfer ownership, and
// you must then make sure that code calling the function upholds this semantics.
// c++ doesn't do any of these for you
//113. sometimes you can do this through parameter types (references are virtually
// always aliases, and const pointers are always aliases)
//114. sometime you have to do it through naming conventions - e.g. "adopt"/"orphan"/"create"
// in the names of the functions that transfer ownership
//115. an assignment operator's const reference parameter signifies that we are not
// taking ownership of its internal state (there are some very rare exceptions to this)
//116. as an aside, its worth mentioning that there are occasions where copying objects
// to maintain ownership semantics is too expensive. in this situation, a technique called
// 'reference counting' can be used

c++ review in a blast (core)


//1. virutal function
//2. abstract base class, pure virtual function
//3. pure virtual definition is allowed
//4. reference - i is x itself
//5. when reference, when pointer
//6. reference - no "reseating", on the skin, pointers on the inside
//7. reference - exception "sentinel" reference, null pointer
//8. handle to an object - way to let you get to another object
//9. class, struct
//10. inline function, why inline not #define
//11. constructor calls in an inheritance hierarchy
//12. destructor calls in an inheritance hierarchy
//13. the need for virtual destructor - type of the pointer is that of the base / memory leak
//14. pure virtual destructor is not allowed
//15. constructors cannot be virtual - virtual table not yet available in memory
//16. overhead in searching virtual table
//17. virtual keyword need not be restated
//18. functionality can be overridden in the derived class
//19. dynamic binding - calls to virtual functions are resolve at runtime
//20. prominent reason to use virtual function - to have different functionality in the derived
//21. non-virtual member functions are resolved at compile time]
//22. virtual constructor for each class (vptr at start of object, vtable class-specific)
//23. inline function - the function is expanded in the calling block
//24. not treated as separate unit like other functions
//25. compiler is free to decide
//26. if it has large chunk of code, it will not be considered inline
//27. in function declaration, inline keyword is not used
//29. inline keyword in function definition
//30. actually not necessary, if function is defined in declaration with small chunk of code
//31. static data types, static functions
//32. differences between a static member function and a non-static member function
//33. a static member function can access static member data, other static member function,
// data and function outside the class.
//34. no instantiation needed
//35. cannot be virtual
//36. cannot have access to the 'this' pointer of the class
//37. 'this' pointer - object x of class A with non-static member function f()
// in the call to x.f() - the keyword 'this' in the body of f() stores the address of x
//38. cannot declare it or assignment to it
//39. static member function does not have 'this' pointer
//40. type of 'this' pointer is X* const
//41. if member function is declared with 'const' qualifier, type of 'this' is const X* const
//42. a const this pointer can only be used with const member functions
//43. data members of the class will be constant within that function
//44. member mutable - volatile
//45. 'this' is passed as hidden argument to all non-static member functions
// and is available as local variable within the body of all non-static member functions
//46. this->a = a;
//47. 'this' may not be necessary for visible member functions.
//48. can use it to differentiate parameter and member data with the same name
//49. address operator