#include <iostream>
using namespace std;


class Printer
{
public:
    template<typename T>//类的成员函数是模板
    void print(const T& t)
    {
        cout << t << endl;
    }

    template<typename T>
    void print(int a, const T& t)
    {
        cout << a << t << endl;
    }
};

int main()
{
    Printer p;
    p.print<const char*>("abc");                //类成员函数是模板的调用方式
    p.print("abc");                            //编译器推断参数模板类型
    p.print(2, "abc");                        //类模板成员函数重载
    getchar();
    return 0;
}

 

相关文章:

  • 1970-01-01
  • 2021-12-28
  • 2022-01-02
  • 2021-04-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-12-13
猜你喜欢
  • 2021-05-25
  • 2021-09-09
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案