您的位置:首页 > 其它

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

2012-04-19 21:59 357 查看
#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;
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: