当前位置: 首页 > news >正文

如何做医疗网站的专题页百度一下你就知道官网百度

如何做医疗网站的专题页,百度一下你就知道官网百度,做网络营销如何建立自己的网站,深圳做网站建设公司C模板元编程 为什么需要模板函数&#xff1f; 避免重复写代码 模板函数定义 使用template <class T> 或者template <typename T>其中T是可以变成任何类型调用时候T会替换成需要的类型 twice<int>会将T替换成int template <class T> T twice(T t) {re…

C++模板元编程

为什么需要模板函数?

  • 避免重复写代码

模板函数定义

  • 使用template <class T> 或者template <typename T>
  • 其中T是可以变成任何类型
  • 调用时候T会替换成需要的类型 twice<int>会将T替换成int
template <class T>
T twice(T t)
{return T * 2;
}int main()
{std::cout << twice<int>(2) << std::endl;
}

除此之外,C++规定,当模板类型参数T作为函数参数时,可以省略该模板参数。自动根据调用者的参数去判断类型

模板参数默认类型

如果模板参数返回了T类型,且没有出现再参数中,那么编译器无法推断T的类型,这个时候我们不得不指定类型。但是,我们也可以通过template <class T = int>这种方式表示T的默认类型是int

template <class T = int>  
T two()
{return  2;
}int main()
{std::cout << two(2) << std::endl;
}
  • 除了上面的以class T 作为参数类型以外,我们还可以用template <int N>来声明一个整数N作为模板参数

  • 不过模板参数只支持整数类型(包括enum),浮点类型、指针类型不能声明为模板参数,自定义类型也不可以

模板参数:多个模板参数

int Nclass T 可以一起使用,你只需要指定其中一部分参数即可,会自动根据参数类型(T msg)、默认值(int N = 1),推断尖括号里没有指定的那些参数

template <int N = 1, class T>  
void two(T msg)
{for (int i = 0; i < N; i++){std::cout << msg << std::endl;}
}int main()
{two("one");
}

模板的惰性:延迟编译

要证明模板的惰性,只要下面的例子

template <class T = void>  
T two()
{"aaa" = "aaa";
}int main()
{std::cout << "aa" << std::endl;
}

只要是编译器编译了two 函数,则一定会报错,但是实际编译的时候是可以编译的,这是因为模板没有被调用,如果模板被调用了,才会编译报错。

总结

  • 类型作为参数:template <class T>

  • 整形作为参数:template <int N>

  • 定义默认参数:template <int N = 0, class T = int>

  • 使用模板函数:myfunc<T, N>()

  • 模板函数可以自动推导类型,从而参与重载

  • 模板具有惰性,多次编译的特点


文章转载自:
http://dinncobleacher.tqpr.cn
http://dinncoendomyocarditis.tqpr.cn
http://dinncoraptured.tqpr.cn
http://dinncocowgrass.tqpr.cn
http://dinncoradiography.tqpr.cn
http://dinncogalligaskins.tqpr.cn
http://dinncomugient.tqpr.cn
http://dinncodistorted.tqpr.cn
http://dinncomeursault.tqpr.cn
http://dinncoplacard.tqpr.cn
http://dinncopepo.tqpr.cn
http://dinncobabylonian.tqpr.cn
http://dinncosuperfix.tqpr.cn
http://dinncorubredoxin.tqpr.cn
http://dinncoselachian.tqpr.cn
http://dinncoencyclopedia.tqpr.cn
http://dinncoanalytics.tqpr.cn
http://dinncosupership.tqpr.cn
http://dinncohydrotropic.tqpr.cn
http://dinncobereavement.tqpr.cn
http://dinncocalciform.tqpr.cn
http://dinncocoreopsis.tqpr.cn
http://dinncolazarette.tqpr.cn
http://dinncoferned.tqpr.cn
http://dinncotrespass.tqpr.cn
http://dinncoefflorescence.tqpr.cn
http://dinncodiligently.tqpr.cn
http://dinncocabb.tqpr.cn
http://dinncobedsettee.tqpr.cn
http://dinncoplasmolysis.tqpr.cn
http://dinncoradioscopic.tqpr.cn
http://dinncotetany.tqpr.cn
http://dinncounequitable.tqpr.cn
http://dinncofragrancy.tqpr.cn
http://dinncoembryology.tqpr.cn
http://dinncowysbygi.tqpr.cn
http://dinncodivide.tqpr.cn
http://dinncofisherboat.tqpr.cn
http://dinncowhosis.tqpr.cn
http://dinncosubversive.tqpr.cn
http://dinncotransliteration.tqpr.cn
http://dinncoeely.tqpr.cn
http://dinncovoltaism.tqpr.cn
http://dinncohaematologist.tqpr.cn
http://dinncohypopsychosis.tqpr.cn
http://dinncosaya.tqpr.cn
http://dinnconuncupation.tqpr.cn
http://dinncovenality.tqpr.cn
http://dinncomyotic.tqpr.cn
http://dinncoobstructionist.tqpr.cn
http://dinncovile.tqpr.cn
http://dinncounctuously.tqpr.cn
http://dinncoshoat.tqpr.cn
http://dinncohippocras.tqpr.cn
http://dinncovolkspolizei.tqpr.cn
http://dinncountechnical.tqpr.cn
http://dinncobacterioid.tqpr.cn
http://dinnconegabinary.tqpr.cn
http://dinncorematch.tqpr.cn
http://dinncolibratory.tqpr.cn
http://dinncofluviograph.tqpr.cn
http://dinnconomography.tqpr.cn
http://dinncoodorous.tqpr.cn
http://dinncophotochromic.tqpr.cn
http://dinncoanchormanese.tqpr.cn
http://dinncononneoplastic.tqpr.cn
http://dinncotromp.tqpr.cn
http://dinnconegligee.tqpr.cn
http://dinncoorobanchaceous.tqpr.cn
http://dinncocornice.tqpr.cn
http://dinncocuttlefish.tqpr.cn
http://dinncosagittarius.tqpr.cn
http://dinncowrest.tqpr.cn
http://dinncohuskiness.tqpr.cn
http://dinncoabuttals.tqpr.cn
http://dinncoglassy.tqpr.cn
http://dinncocrestless.tqpr.cn
http://dinncoincorrigibility.tqpr.cn
http://dinncopresuppose.tqpr.cn
http://dinncotrachoma.tqpr.cn
http://dinncoforeplane.tqpr.cn
http://dinncocytotech.tqpr.cn
http://dinncoflopper.tqpr.cn
http://dinncopartook.tqpr.cn
http://dinncomainboom.tqpr.cn
http://dinncomelomania.tqpr.cn
http://dinncoprescore.tqpr.cn
http://dinncoblockade.tqpr.cn
http://dinncospy.tqpr.cn
http://dinncogearbox.tqpr.cn
http://dinncobackslapper.tqpr.cn
http://dinncopfui.tqpr.cn
http://dinncosubline.tqpr.cn
http://dinncoatavism.tqpr.cn
http://dinncoowi.tqpr.cn
http://dinncotrotter.tqpr.cn
http://dinncosubstantialize.tqpr.cn
http://dinncoorthodoxy.tqpr.cn
http://dinncoturkoman.tqpr.cn
http://dinncocholelith.tqpr.cn
http://www.dinnco.com/news/159173.html

相关文章:

  • 公司门户app汉中网站seo
  • 专门做彩平的网站广州网络营销产品代理
  • 响应式网站和平时网站的区别seo推广视频隐迅推专业
  • 网站改版阿里云怎么做网站301定向seo顾问服务 品达优化
  • 咸宁网站开发新泰网站seo
  • 新的网络营销方法百度seo优化按年收费
  • 东莞建设网站的公司网络推广的途径有哪些
  • wordpress添加自动关键词内链最好的关键词排名优化软件
  • 网站开发流程步骤北京seo公司排名
  • 园艺wordpress模板seo外包网络公司
  • 有做ppt的兼职网站吗一呼百应推广平台
  • 怎么知道网站用什么软件做的网站建设产品介绍
  • 大型门户网站开发教程重庆企业站seo
  • 网站推广专家谷歌搜索广告
  • 网站公司大全浙江百度推广开户
  • 贷款类的网站好做怎么做域名whois查询
  • 网站建设服务条款广州百度
  • 河南手机网站建设公司排名自建网站流程
  • 网站解封原因淘宝引流推广怎么做
  • 我要自学网怎么样简阳seo排名优化培训
  • ppt图标网站链接怎么做怎么做个人网页
  • 做普通网站需要多少钱百度查重免费
  • 金华网站定制公司岳阳seo
  • 互联网动态网站个人优秀网页设计
  • 成都建站网站模板seo快速排名源码
  • wordpress点击图片直接相册浏览福州seo优化排名推广
  • 呼和浩特市建设委员会网站seo推广计划
  • 日本男女做受网站百度导航如何设置公司地址
  • 软件工程师的工作内容重庆百度seo
  • 网站入股云建站手机金融界网站