首页 > 其他 > 详细

使用模板实现编译期间多态(类名当参数)

时间:2017-02-07 18:44:33      阅读:225      评论:0      收藏:0      [点我收藏+]
#include <iostream>
using namespace std;

class DemoOne{
public:
	void f(bool someParm=true){ cout<<"DemoOne f functions\n";}
	void g(){ cout<<"DemoOne g functions\n";}
	// other functions...
};


class DemoTwo{
public:
	void f(){ cout<<"DemoTwo f functions\n";}
	void g(double a=1.12,double b=1.123){ cout<<"DemoTwo g functions\n";}
	// other functions...
};

template<typename T>
void h(T& t){
	t.f();
	t.g();
}

int _tmain(int argc, _TCHAR* argv[])
{
	DemoOne one;
	DemoTwo two;
	h(one);
	h(two);
	
	return 0;
}

 

技术分享

 

http://www.cnblogs.com/rollenholt/archive/2012/04/19/2458017.html

使用模板实现编译期间多态(类名当参数)

原文:http://www.cnblogs.com/findumars/p/6375467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!