zoukankan      html  css  js  c++  java
  • C++之类模板

    【类模板】
    
    template<class T>
    class MyArray{
    public:
        void display();//若是类内定义则没什么特别的:void display(){...}
    private:
        T *m_pArr;
    };
    //实现
    template<class T>
    void MyArry<T>::display(){
    ...
    }
    //使用
    MyArray<int> arr;
    arr.display();
    【多参数的类模板】
    
    template <typename T,int KSize>
    class Container{
    public:
        void display();
    private:
        T m_obj;
    }
    //实现
    template <typename T,int KSize>
    void Container<T,KSize>::display(){
        for(int i=0;i<KSize;i++){
            cout << m_obj << endl;
        }
    }
    //使用
    Container<int,10> ct1;
    ct1.display();
    【模板代码不能分离编译,必须都写在.h文件中】
    无欲则刚 关心则乱
  • 相关阅读:
    孤儿进程与僵尸进程
    python with as的用法
    工作目录与os.getcwd()
    内置模块
    迭代器,生成器
    表达式,语句
    字符流
    字节流
    File
    触发器的操作
  • 原文地址:https://www.cnblogs.com/xjyxp/p/11242668.html
Copyright © 2011-2022 走看看