C++基础4

来源:互联网 发布:电子电路仿真软件 编辑:程序博客网 时间:2024/04/29 07:25

模版

 

函数模版声明

template<class T>

T max(T X,T Y)

{

  return (x>y)?x:y;

}

 

注意:实例化T的各模版实参之间必须保持完全一致的类型

 

模版类定义

template<class Type>

class stack

{

void push(Type ch);

Type pop();

}

 

类外定义push pop

template<class Type>

void stack<Type>::push(Type ob){}

 

template<class Type>

Type stack<Type>::pop(){}

 

 

原创粉丝点击