使用模板实现编译期间多态
2012-04-19 21:59 Rollen Holt 阅读(845) 评论(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://wenchao.ren
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员
==============================================================================

浙公网安备 33010602011771号