#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; }

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

相关文章:

  • 2021-12-15
  • 2022-12-23
  • 2021-09-28
  • 2021-08-21
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案