早教吧 育儿知识 作业答案 考试题库 百科 知识分享

下列模板的定义是否合法的?若为非法的,请简单扼要说明理由。(1)templateclassContainer4;(2)templateclassContainer5{……Vfun(Tinput){......}};(3)templateVfun(Tinput,Toutput){……}

题目详情
下列模板的定义是否合法的?若为非法的,请简单扼要说明理由。
(1) template class Container4;
(2) template class Container5{
……
V fun(T input){......}
} ;

(3) template
V fun(T input, T output){……}
▼优质解答
答案和解析
1, 为非法的。参考函数参数定义。
2,合法的。
3,合法的。但是调用时需要申明用什么返回值。
例如:double v = fun(1, 2);
以帮助编译器实例化函数,然后链接器才有的链接。