This is the replication of examples in book Introduction to C++ for Financial Engineers An Object-Oriented Approach.
Only the following chapters are contained in this repo:
- Chapter 2: Mechanics of C++
- Chapter 3: C++ fundamentals
- Chapter 5: Operator overloading
- Chapter 6: Memory management
- Chapter 7: Inheritance
- Chapter 9: Run-time behavior and exception handling
- Chapter 10: STL
- Only use
friend
when declare a function, but not when define a function. - No type is needed when declare and define constructors.
- Memeber function names in class cannot be the same with member data name.
- Declare type
ostream&
when overloading<<
. <<
is a binary operator with first arguement of typeostream&
and second arguement string.
->
is used for pointer to call class memebers, equivalent to(*pointer).member
virtual
specifier specifies virtual function. The derived class is optional to override this memeber function.virtual void func()=0
define a pure virtual function or pure virtual method which is required to be implemented by a derived class if the derived class is not abstract.- When declare function with function pointers as argument, it must contain the types the function's arguments. For example,
(*func)(double, int)
.
- Remember to define read-only functions as
const
, especially in base class. - Remember to declare and define destructor in header file.
size
methid invector
class returnunsigned int
object. Define counter correspondingly when use it in the loop.- Reference is a name constant for an address, acts mostly like a pointer. However, oo explicit dereferencing operator
*
should be used when return the values. Furthermore, to assign an address of a variable to a reference variable, no address-of operator&
is needed.
- When call a template function, one can explicitly specify the type. C++ support implicit template parameter deduction, so one can ignore the type as well.