c++类模板和函数模板的问题
#include"stdafx.h"#include<iostream>usingnamespacestd;template<typenametype1>type1ret...
#include "stdafx.h"
#include <iostream>
using namespace std;
template<typename type1>
type1 retun(identity&a);
template<class type1,class type2>
class identity
{
public:
identity();
void set_information();
void display();
friend retun(identity&a);
private:
type1 num;
type2 total;
};
template <class type1,class type2>
identity::identity()
{
num=0;
total=0;
}
template<class type1,class type2>
void identity::set_information()
{
cout<<"请输入信息"<<endl;
cin>>num>>total;
}
template<class type1,class type2>
void identity::display()
{
cout<<num<<" "<<tatal;
}
template<typename type1>
type1 retun(identity&a)
{
return a.num;
}
int main()
{
identity<long,int> a;
a.set_information();
a.display();
cout<<endl;
cout<<retun<long> (a);
system("PAUSE");
return 0;
}
调试的时候一堆错误·······························我也看不明他什么意思········请问大神这里什么地方出问题?应该怎么改? 展开
#include <iostream>
using namespace std;
template<typename type1>
type1 retun(identity&a);
template<class type1,class type2>
class identity
{
public:
identity();
void set_information();
void display();
friend retun(identity&a);
private:
type1 num;
type2 total;
};
template <class type1,class type2>
identity::identity()
{
num=0;
total=0;
}
template<class type1,class type2>
void identity::set_information()
{
cout<<"请输入信息"<<endl;
cin>>num>>total;
}
template<class type1,class type2>
void identity::display()
{
cout<<num<<" "<<tatal;
}
template<typename type1>
type1 retun(identity&a)
{
return a.num;
}
int main()
{
identity<long,int> a;
a.set_information();
a.display();
cout<<endl;
cout<<retun<long> (a);
system("PAUSE");
return 0;
}
调试的时候一堆错误·······························我也看不明他什么意思········请问大神这里什么地方出问题?应该怎么改? 展开
展开全部
template <class type1,class type2>
class myTmpClass
{
public:
myTmpClass();
void set_information();
void display();
type1 ret_num(myTmpClass &a);
private:
type1 num;
type2 total;
};
template <class type1,class type2>
myTmpClass<type1,type2>::myTmpClass()
{
num=0;
total=0;
}
template<class type1,class type2>
void myTmpClass<type1,type2>::set_information()
{
cout<<"请输入信息"<<endl;
cin>>num>>total;
}
template<class type1,class type2>
void myTmpClass<type1,type2>::display()
{
cout<<"num = "<<num<<","<<"total = "<<total<<endl;
}
template<class type1,class type2>
type1 myTmpClass<type1,type2>::ret_num(myTmpClass &a)
{
return a.num;
}
int main()
{
myTmpClass<long,int> a;
a.set_information();
a.display();
cout<<endl;
cout<<a.ret_num(a);
system("PAUSE");
return 0;
}
你这样试试。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询