c++学习笔记(模板)(一)

Posted on 2011-09-13 23:56  洪庸  阅读(108)  评论(0编辑  收藏  举报

模板定义


template <typename T>

int compare(const T &v1, const T &v2){

}


inline template <typename T> T min (const T&, const T&);



类模板定义


template <class Type> class Queue{}



非类型模板形参

template < class T,size_t N> void array_init(T (&parm)[N]){

    for(size_t i=0; i != N; ++i){

parm[i] = 0;

    }

}

int x[42];

array_init(x);



模板在使用时进行实例化


包含编译


//header file 

#ifndef _H

#define _H


template <class T> int compare(const T&, const T&);


#include "h.cc"

#endif



//cc file

template <class T> int compare (const T &v1, const T &v2){

//bala bala 

}



版权声明:本文为博主原创文章,未经博主允许不得转载。

Copyright © 2024 洪庸
Powered by .NET 8.0 on Kubernetes