c++一些语法模板
函数模板特
template <class T>
int compare(T v1,T v2)
{
if(v1<v2)
return -1;
else if(v1>v2)
return 1;
else
return 0;
} template <>
int compare<char *>(char * s1,char * s2)
{
return strcmp(s1,s2);
}
类模板的特化
template <class T>
class test
{
public:
void operator()()
{
cout<<"test<T>"<<endl;
}
}; template <> class test<char>
{
public:
void operator()()
{
cout<<"test<char>"<<endl;
}
};
模板的偏特化
template <class T,class O>
struct testClass
{
testClass(){cout<<"I,O"<<endl;}
}; template <class T>
struct testClass<T *,T *>
{
testClass(){cout<<"T*,T*"<<endl;}
};
成员模板
template <class T>
class v
{
public:
template <class T1>
void insert(int position ,T1 t)
{
cout<<"insertion"<<endl;
}
};
依据前面一个模板确定当前的模板參数
template <class T,class S=vector<T> >
class test
{
public:
test(){cout<<"test"<<endl;}
private:
S t;
}
模板与友元的绑定
template <class T>
class Queue
{
friend bool operator == <T> (const Queue <T> &t1,const Queue <T> &t2)
{
cout<<"T,T"<<endl;
return true;
}
};
内联函数模板
inline template <typename T> T min(const T& a,const T & b)
{
return a<b?a:b;
}
注意inline 和template的位置不能互换
模板内部指定类型
template <class T>
class test
{
public:
typename T::size_type t; //模板内部定义类型
};
非类型模板形參
template <class T,size_t N>
void arr(T (¶)[N])
{
int i=0;
for(i=0;i<N;i++)
cout<<para[i]<<endl;
};
版权声明:本文博客原创文章,博客,未经同意,不得转载。
c++一些语法模板的更多相关文章
- php特殊语法--模板引擎中比较常见
<?php $a=array(1,2,0); foreach ($a as $v): if($v>1): ?> 5 <?php endif; endforeach; ?> ...
- markdown语法模板
(GitHub-Flavored) Markdown Editor Basic useful feature list: Ctrl+S / Cmd+S to save the file Ctrl+Sh ...
- 基于typescript编写vue的ts文件语法模板
1 <template> 2 <div> 3 <input v-model="msg"> 4 <p>prop: {{ propMes ...
- 快速生成组件语法模板的插件:Auto Close Tag
好家伙, 这是一个"标签闭合"插件 Auto Close Tag的安装: 来到VScode的拓展 安装后, 在其中输入一个左标签符号"<",随后会出现提示 ...
- django模板语法
Django 模板语法 Django 模板语法 一.模板 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法 模板语法变量:{{ }}在Django模板中遍历复杂 ...
- Django 2.0 学习(12):Django 模板语法
Django 模板语法 一.模板 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法 模板语法变量:{{ }} 在Django模板中遍历复杂数据结构的关键是句点字 ...
- [转帖]helm模板文件chart编写语法详解
helm模板文件chart编写语法详解 https://blog.51cto.com/qujunorz/2421328 需要学习一下. charts编写介绍 开始 快速创建一个chart模板,helm ...
- ES5与ES6常用语法教程之 ③模板字符串、判断字符串是否包含其它字符串
这部分教程我们主要讲解以下几个常用语法 模板字符串 带标签的模板字符串 判断字符串中是否包含其他字符串 给函数设置默认值 模板字符串 老式的拼接字符串方法 let dessert = '
- 【转】Django 模板语法
转自:https://www.cnblogs.com/love9527/p/9077863.html Django 模板语法 一.模板 只要是在html里面有模板语法就不是html文件了,这样的文件就 ...
随机推荐
- CodeForces 462B Appleman and Card Game(贪心)
题目链接:http://codeforces.com/problemset/problem/462/B Appleman has n cards. Each card has an uppercase ...
- 操作引入xml文件的书包(定位到指定节点)
定位到指定节点:e0.1 <chtml><we>@{_samples/test.xml:HtokID=e0.1}</we></chtml> 上述表达式表 ...
- c#引用web.config中的ConnectionString
c#引用web.config中的ConnectionString <connectionStrings> <add name="JKXTConnectionString& ...
- iOS进阶面试题----经典10道
OneV‘s Den在博客里出了10道iOS面试题,用他的话是:"列出了十个应聘Leader级别的高级Cocoa/CocoaTouch开发工程师所应该掌握和理解的技术" . 在这 ...
- HTTP协议--简析
HTTP--超文本传输协议(HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议,是所有的www文件都必须遵守的标准. 要想成为优秀的web开发人员,必须熟悉H ...
- Visual Studio 必备神器---转
会使用工具是人类文明的一大进步,今天敏捷大行其道,好的工具可以大大的提高生产力,这里说的工具都是VS平台上的扩展工具,一些机械的部分可以交给工具去处理,自己多关注其他部分.下面分享下我觉得不错的工具, ...
- 一个与Log4j相关的死锁(转)
这个死锁的原因:一个动作需要两个临界对象.静态同步方法,就是一个临界对象.这种场景,静态同步方法每次只能有一个线程持有.如果存在另一个临界对象,静态同步方法中也需要获取这个临界对象.即一个动作需要两个 ...
- Problem E: Erratic Ants
这个题没过……!题意:小蚂蚁向四周走,让你在他走过的路中寻找最短路,其中可以反向主要思路:建立想对应的图,寻找最短路径,其中错了好多次,到最后时间没过(1.没有考录反向2.没有考虑走过的路要标记……! ...
- HDU4712-----Hamming Distance------超级大水题
本文出自:http://blog.csdn.net/dr5459 题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4712 题目意思: 海明距离:任意两个 ...
- delphi 网页提交按钮执行点击事件
遍历即可实现,下列代码仅供参考: var i: integer; T: OleVariant; begin T := WebBrowser1.Document; do begin if T.all.i ...