类模板的问题
                 	
                        发表在C++图书答疑
                        2018-06-05                                                
                    		
                            《C++从入门到精通(第3版)》第12章  模板                                                	
                        
                        
                    
                    
                    	是否精华
                    	是
                    	否
                    
                    
                    
                            版块置顶:
                            是
                            否
                        
                    #include <iostream >
using namespace std;
/*类模板的一般定义如下:
 template<类型形式参数列表>
 class 类模板名
 {
  ...//类模板体
 }
*/
/*类模板成员函数的定义如下:
 template<类型形式参数列表>
 返回类型 类模板名 <类型名列表>::成员函数名(形式参数列表)
 {
  ...//函数体
 }
*/
template <class type1,class type2>
class Mytemplate
{
 type1 x;
 type2 y;
public:
 Mytemplate(type1 x1,type2 y1)
 {
       x=x1;
    y=y1;
 }
 void dispay()
 {
     cout<<x<<' '<<y<<endl;
 }
};
//模板成员函数定义
//Mytemplate<type1,type2>::Mytemplate(type1 x1,type2 y1)
//{
// x=x1;
// y=y1;
//}
//void Mytemplate<type1,type2>::dispay()
//{
// cout<<x<<''<<y<<endl;
//}
void main()
{
 int a=12345;
 double b=9.8709;
 Mytemplate<int,double>   newobject(a,b);//这里相当于创建的一个对象newobj,这里a指定为int,b指定为double
 newobject.dispay();
 
 getchar();
}
请问如何把成员函数的定义放在外面??
于2018-06-05 17:45:37编辑
        
        	
        
        
    
 
	
                                                 VIP会员
VIP会员 购物车
购物车


 私信
                         私信 
                     发表新帖
发表新帖 立即签到
立即签到 
        		  
        		 
         		 关注
关注
                  回复
 回复 支持(
                	支持( 反对(
                    反对( 
                







 
                     
                     
					 
						 
						 
						 
						