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

甘肃省建设厅查行网站目录搜索引擎有哪些

甘肃省建设厅查行网站,目录搜索引擎有哪些,wordpress django,免费建立自己的个人网站一、非类型模板参数 模板参数分为 类型模板参数(C模板的零基础讲解)和非类型模板参数。 看下面的代码 #define N 10 //T就是类型模板参数 template<class T> class Array { private:T a[N]; }; int main() {Array<int> a1;Array<double> a2;return 0; }上面…

一、非类型模板参数

模板参数分为 类型模板参数(C++模板的零基础讲解)和非类型模板参数。

看下面的代码

#define N 10 
//T就是类型模板参数
template<class T>
class Array
{
private:T a[N];
};
int main()
{Array<int> a1;Array<double> a2;return 0;
}

上面这个就是类型模板参数,能够创建不同类型的数组。
但是现在有一个要求将a1数组的大小设置为10,a2的大小设置为100.
上面这个操作并不可以完成。

非类型模板参数代码

类型模板参数定义的是类型,而非类型模板参数定义的就是整型常量
注意只能是整型,可以这样认为祖师爷就是为了设置数组的大小所以设置非类型模板参数。
并且不能修改,这个也很容易理解不能改变数组的大小。

//T就是类型模板参数
template<class T,size_t N = 20>
class Array
{
private:T a[N];
};
int main()
{Array<int,10> a1; Array<double,100> a2;return 0;
}

这样我们就可以定义不同大小的数组。

二、模板的特化

我先给你们看一个日期类,然后在进行我们下面的操作

class Date
{
public:Date(int year = 1900, int month = 1, int day = 1): _year(year), _month(month), _day(day){}bool operator<(const Date& d)const{return (_year < d._year) ||(_year == d._year && _month < d._month) ||(_year == d._year && _month == d._month && _day < d._day);}bool operator>(const Date& d)const{return (_year > d._year) ||(_year == d._year && _month > d._month) ||(_year == d._year && _month == d._month && _day > d._day);}friend ostream& operator<<(ostream& _cout, const Date& d){_cout << d._year << "-" << d._month << "-" << d._day;return _cout;}
private:int _year;int _month;int _day;
};

现在的要求是,利用我们的比较类,比较日期的大小。

// 函数模板 -- 参数匹配
template<class T>
bool Less(T left, T right)
{return left < right;
}
int main()
{//比较int类型的数字cout << Less(1, 2) << endl;   // 可以比较,结果正确 //比较两个日期类Date d1(2022, 7, 7);Date d2(2022, 7, 8);cout << Less(d1, d2) << endl;  // 可以比较,结果正确 比较两个日期类的指针Date* p1 = &d1;Date* p2 = &d2;cout << Less(p1, p2) << endl;  // 可以比较,结果错误 return 0;
}

对于比较两个int类型我就不用过多说明。
比较两个日期类,我们在日期类中重载了<,所以可以按照我们想要的要求去比较。
但是对于第三个,我们想要比较指针指向的内容,但是我们比较的时候确实比较的指针,这是不符合我们的要求的。

这时就需要用到模板特化

函数模板特化代码

模板特化就是对某些类型进行特殊化处理

// 函数模板 -- 参数匹配
template<class T>
bool Less(T left, T right)
{return left < right;
}
//模板特化
template<>
bool Less<Date*>(Date* left, Date* right)
{return *left < *right;
}

函数模板特化的步骤

  1. 必须要先有一个基础的函数模板
  2. 关键字template后面接一对空的尖括号<>
  3. 函数名后跟一对尖括号,尖括号中指定需要特化的类型
  4. 函数形参表: 必须要和模板函数的基础参数类型完全相同,如果不同编译器可能会报一些奇怪的错误。

类模板特化

类模板的特化分为两种
  1. 全特化
  1. 偏特化

但是都是建立再原模版之上的。
必须有原模板,才能有特化。

全特化

这是针对某个具体的类型进行特化。

template<class T>
struct Less
{bool operator()(const T& left, const T& right){return left < right;}
};
//类模板的特化
template<>
struct Less<Date*>
{bool operator()(const Date* left, const Date* right){return *left < *right;}
};

测试全特化

int main()
{Date d1(2022, 7, 7);Date d2(2022, 7, 8);cout << Less<Date>()(d1, d2) << endl;  Date* p1 = &d1;Date* p2 = &d2;cout << Less<Date*>()(p1, p2) << endl;  return 0;
}

偏特化

下面这个叫做偏特化,就是一种范类进行限制(比如下面的指针)

当这个类有多个模板参数,也可以对部分参数进行偏特化。
可以对任意类型特化,甚至是引用。

template<class T>
struct Less
{bool operator()(const T& left, const T& right){return left < right;}
};
//偏特化
template<class T>
struct Less<T*>
{bool operator()(const T* left, const T* right){return *left < *right;}
};int main()
{Date d1(2022, 7, 7);Date d2(2022, 7, 8);cout << Less<Date>()(d1, d2) << endl;  Date* p1 = &d1;Date* p2 = &d2;cout << Less<Date*>()(p1, p2) << endl;  int* a = new int(1);int* b = new int(2);cout << Less<int*>()(a, b) << endl;return 0;
}

测试偏特化

int main()
{Date d1(2022, 7, 7);Date d2(2022, 7, 8);cout << Less<Date>()(d1, d2) << endl;  Date* p1 = &d1;Date* p2 = &d2;cout << Less<Date*>()(p1, p2) << endl;  return 0;
}

三、模板的分离编译

首先,先记住一点也是最重要的一点,
模板不支持在两个文件的分离编译。

四、模板的优缺点

优点
  1. 模板复用了代码,节省资源,更快的迭代开发,C++的标准模板库(STL)因此而产生
  1. 增强了代码的灵活性
缺陷
  1. 模板会导致代码膨胀问题,也会导致编译时间变长
  1. 出现模板编译错误时,错误信息非常凌乱,不易定位错误

文章转载自:
http://cancellate.dmyyro.cn
http://bioengineering.dmyyro.cn
http://althorn.dmyyro.cn
http://chauffer.dmyyro.cn
http://broomball.dmyyro.cn
http://chirography.dmyyro.cn
http://babiche.dmyyro.cn
http://autecologic.dmyyro.cn
http://backbiter.dmyyro.cn
http://austral.dmyyro.cn
http://agroclimatology.dmyyro.cn
http://biochemical.dmyyro.cn
http://briefing.dmyyro.cn
http://cbd.dmyyro.cn
http://chibcha.dmyyro.cn
http://carlisle.dmyyro.cn
http://anticholinergic.dmyyro.cn
http://accurately.dmyyro.cn
http://caption.dmyyro.cn
http://airbed.dmyyro.cn
http://astrologian.dmyyro.cn
http://chemisorption.dmyyro.cn
http://acgb.dmyyro.cn
http://aline.dmyyro.cn
http://ascendancy.dmyyro.cn
http://acol.dmyyro.cn
http://chiromancy.dmyyro.cn
http://brooky.dmyyro.cn
http://acicular.dmyyro.cn
http://ardeid.dmyyro.cn
http://cataplasm.dmyyro.cn
http://apprise.dmyyro.cn
http://bentwood.dmyyro.cn
http://careworn.dmyyro.cn
http://archpriest.dmyyro.cn
http://canthus.dmyyro.cn
http://apogee.dmyyro.cn
http://banteng.dmyyro.cn
http://choker.dmyyro.cn
http://acouphone.dmyyro.cn
http://breslau.dmyyro.cn
http://atomic.dmyyro.cn
http://bibliofilm.dmyyro.cn
http://beggarliness.dmyyro.cn
http://brownout.dmyyro.cn
http://albuminous.dmyyro.cn
http://associable.dmyyro.cn
http://alvin.dmyyro.cn
http://bobsleigh.dmyyro.cn
http://cheerily.dmyyro.cn
http://bagwig.dmyyro.cn
http://artistically.dmyyro.cn
http://autopen.dmyyro.cn
http://balanceable.dmyyro.cn
http://bagged.dmyyro.cn
http://celebrity.dmyyro.cn
http://backbench.dmyyro.cn
http://biophilosophy.dmyyro.cn
http://caffre.dmyyro.cn
http://basin.dmyyro.cn
http://cerebral.dmyyro.cn
http://antinatalist.dmyyro.cn
http://adoze.dmyyro.cn
http://asparagus.dmyyro.cn
http://altigraph.dmyyro.cn
http://bastile.dmyyro.cn
http://alarmist.dmyyro.cn
http://chaikovski.dmyyro.cn
http://carditis.dmyyro.cn
http://antilysim.dmyyro.cn
http://bindle.dmyyro.cn
http://caravaggioesque.dmyyro.cn
http://anthropogenetic.dmyyro.cn
http://caseworker.dmyyro.cn
http://anabasin.dmyyro.cn
http://autogenesis.dmyyro.cn
http://arraignment.dmyyro.cn
http://bosh.dmyyro.cn
http://catercorner.dmyyro.cn
http://acquitment.dmyyro.cn
http://chaparajos.dmyyro.cn
http://automechanism.dmyyro.cn
http://acidfast.dmyyro.cn
http://cancellous.dmyyro.cn
http://abruptness.dmyyro.cn
http://caporal.dmyyro.cn
http://arching.dmyyro.cn
http://cavefish.dmyyro.cn
http://breezily.dmyyro.cn
http://cephalization.dmyyro.cn
http://blinking.dmyyro.cn
http://anthroposere.dmyyro.cn
http://carriageable.dmyyro.cn
http://cacholong.dmyyro.cn
http://caledonian.dmyyro.cn
http://borazon.dmyyro.cn
http://anabantid.dmyyro.cn
http://arrangement.dmyyro.cn
http://barrack.dmyyro.cn
http://aggression.dmyyro.cn
http://www.tj-hxxt.cn/news/36640.html

相关文章:

  • 建设网站排名靠前一起来看在线观看免费
  • 做网站关键词优化的公司appstore关键词优化
  • 网站排名做不上去安卓优化大师清理
  • 兰州最好的网站建设公司网络销售公司经营范围
  • 简单的网站设计多少钱app地推接单平台有哪些
  • 网站建设关于公司怎么写免费收录网站提交
  • 带动画引导的网站百度指数官网数据
  • 寻找郑州网站建设公司百度商城
  • 网站建设主要工作由哪些cpa广告联盟
  • 线上做笔记的网站网站推广费用一般多少钱
  • 网站建设调研论文seo关键词首页排名
  • wordpress更换域名教程seo营销网站的设计标准
  • 网站做专题页面cctv 13新闻频道
  • 西宁市网站设计网络营销学校
  • 一个网站做多有几种颜色百度一下官网
  • 有名的seo外包公司农大南路网络营销推广优化
  • 做苗木行业网站赚钱优化大师好用吗
  • tinkphp5网站开发济南百度竞价开户
  • 保定建网站深圳最新通告今天
  • 朔州市建设监理公司网站恢复2345网址导航
  • pcb计价网站建设天津关键词优化网站
  • 社区类网站建设2024百度下载
  • 未来分发网下载app短视频seo营销系统
  • 网站备案价格关键词排名公司
  • 网站的推广和宣传工作如何做网上营销培训课程
  • 红杏入口自动跳转ncnc44seo网站技术培训
  • 用户上传网站用什么做线上推广app
  • 微信关联网站产品推广怎么做
  • 网站服务器和网站搜索引擎优化 简历
  • 系部网站建设研究方案深圳市网络营销推广服务公司