Skip to content

Notes….



8/25/2010
---------
>>POM#1
Read 10 pages of Modern C++ design.
Realised that it needs more knowledge about templates.
Started with reading the book : C++ Templates, The Complete Guide 2002.chm

>>POM#2
Function templates
function template syntax:
template <typename a1,....>
funnction declaration or definition using T
'typename' introduces type parameter
historical alternative to typename is 'class'.
templates are generated once for each type for which it is used
process of replacing template types with concrete types is called instantiation.
use of function template triggers the 'instatiation'.
templates are compiled twice:
1. once for checking the syntax of the template.
2. second time to check the operations mentioned are valid for 
the type used for template instantiation.

template parameters are determined by the arguments passed at the call time.
no automatic type conversion is allowed.

>>POM#3
Function templates have two kinds of parameters
1. template params - declared in angle brackets, N no. of them can be declared,
 no default template arguments can be specified.
e.g.: template <typename T> // T is template param
2. call params - declared in parenthese after function template name
foo(T p1, T p2) //p1,p2 are call params
call params deduced from template params, so they are related.
function template argument deduction
when template return type cannot be deduced from template and 
call params then needs to be explicitly mentioned.
template argument deduction does not try to determine the return type
another method to just declare one type and then let the compiler deduce the rest.
template <typename RT, typename T1, typename T2> 
inline RT max (T1 const& a, T2 const& b); 
// OK: return type is double, T1 is deduced as int and T2 is deduced as double.
max<double>(4,4.2)    
overloading function templates->overloading resolution revisited
not part of every function call
-- calls to functions thru function ptrs 
-- calls to member functions thru ptr to member functions
not subjected to resolution as they are determined at runtime.

function like macros cannot be overloaded and hence not subjected to reso

8/26/2010
---------
Task for today:
1. chk the tower of hanoi problem
2. chk two design patterns and make notes abt them