加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

c++类模板对象作为函数的三种传入方式

(2024-10-03 02:33:51)
分类: 接口类的哈
c++类模板对象作为函数的三种传入方式c++,类模板对象作为参数,是将一个类模板的 实例传递给函数,或者其它类模板的构造函数。成员函数。

三种方式:

#include
#include
using namespace std;

//定义模板类
template
class student {
public:
student(T1 name, T2 score)
{
this->name = name;
this->score = score;
};
void showme()
{
cout << this->name << this->score << endl;
}

void showme2()
{
cout << this->name << this->score << endl;
}

private:
T1 name;
T2 score;
};
//1确定具体的类型传入
void func1(student & p)
{
p.showme();
}
//2参数模板化
template
void func2(student
{
p.showme2();
}

//3将整个类模板化
template
void func3(T& p)
{
p.showme2();
}

int main() {
student
func1(obj);
func2(obj);
func3(obj);
return 0;
}

c++类模板对象作为函数的三种传入方式————————————————————————
类模板的继承,两种请款处理:
#include
#include
using namespace std;


template
class Base {
public:
T var;

};
// 1/确定基类类型,如果父类是模板,子类是普通类,继承时候确认父类方法
class mycalss :public Base {

};
// 2 确定基类类型,如果父类是模板,子类也是模板类,   继承时候确认父类方法


template
class mycalss1 : public Base {

public:
T var;
u var1;

};


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有