使用模板实现编译期间多态


#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,如需转载请自行联系原作者
上一篇:前后端分离之Spring&Vue单页面开发(2)


下一篇:SpringCloud Alibaba实战二十七 - Oauth2认证服务器自定义异常