日存档: 10月 18, 2010

C++ 模板

模板函数:

template <class T>

T func(T t1)

{

return t1;

}

模板类:

template <class T>

class CA

{

public:

T func(T t1);

}

template <class T>

T CA<T>::func(T t1)

{

return t1;

}

四种不同的对象生存方式

in stack:      int a;

in heap:      int* pa = new int;

global:       int a; (not in a function)

local static:      static int a;