C++学习——模板与异常处理

来源:互联网 发布:淘宝怎么避免虚假交易 编辑:程序博客网 时间:2024/06/05 07:30
模板

函数模板
template<class T> mindt(T x,T y)
{

};

mindt(1,2);
mindt(0.1,0.2);

类模板
template<class T> class test{
T data[100];
....
};

test <int> dt1;
test <double> dt2;

异常处理
try{
     if(a) throw "error1";
     if(b) throw 1;
     if(c) throe 2.34;
}
catch(char *e)//对应错误a,抛出的是字符串
{}
catch(int e)//对应错误b,抛出的是int型
{}
catch(…)//对应错误c,抛出类型不是以上类型
{} 
0 0
原创粉丝点击