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

陕西省城乡住房建设部网站网站推广找

陕西省城乡住房建设部网站,网站推广找,网站建设兼职在哪找,wordpress和z-blog模板的右尖括号 在 c98/03 的泛型编程中,模板实例化有一个很烦琐的地方,那就是连续两个右尖括号(>>)会被编译器解释成右移操作符,而不是模板参数表的结束,所以需要中间加个空格进行分割,…

模板的右尖括号

在 c++98/03 的泛型编程中,模板实例化有一个很烦琐的地方,那就是连续两个右尖括号(>>)会被编译器解释成右移操作符,而不是模板参数表的结束,所以需要中间加个空格进行分割,避免发生编译错误。

int main() {std::vector<std::vector<int>> a; // errorstd::vector<std::vector<int> > b; // ok
}

现在在 c++11 中,这种限制终于被取消了。在 c++11 标准中,要求编译器对模板的右尖括号做单独处理,使编译器能够正确判断出 >> 是一个右移操作符还是模板参数表的结束标记(delimiter,界定符)。

template <typename T>
struct Foo
{typedef T type;
};template <typename T>
class A
{// ...
};int main(void)
{Foo<A<int>>::type xx;  return 0;
}

模板的别名—using 定义别名

大家都知道,在 c++ 中可以通过 typedef 重定义一个类型,被重定义的类型并不是一个新的类型,仅仅只是原有的类型取了一个新的名字。但是使用 typedef 存在两个问题:

  • 对于复杂类型而言,使用 typedef 重定义相对繁琐;
  • typedef 的定义方法和变量的声明类似,这种写法凸显了 c/c++ 中的语法一致性,但有时却会增加代码的阅读难度;
  • typedef 无法重定义一个模板。

c++11 引入了 using,using 的别名语法覆盖了 typedef 的全部功能,可以轻松的定义别名而不是使用繁琐的 typedef。

typedef unsigned int uint_t;  // before c++11
using uint_t = unsigned int;  // c++11typedef std::vector<std::vector<int>> vvi; // before c++11
using vvi = std::vector<std::vector<int>>; // c++11

使用 using 明显简洁并且易读。

定义函数指针之类的操作:

typedef void (*func)(int, int); // 啥玩意,看不懂
using func = void (*)(int, int); // 起码比 typedef 容易看的懂吧

上面的代码使用 using 起码比 typedef 容易看的懂一些吧,但是我还是看不懂,因为我从来不用这种来表示函数指针,用 std::function()std::bind()std::placeholder()、lambda 表达式它不香吗。

函数模板的默认模板参数

c++11 之前只有类模板支持默认模板参数,函数模板是不支持默认模板参数的,c++11 后都支持。以下是 c++11 后支持的写法的示例:

// 类模板
template <typename T, typename U=int>
class A {T value;  
};template <typename T=int, typename U> // error
class A {T value;  
};

类模板的默认模板参数必须从右往左定义,即模板参数必须写在参数表的最后,而函数模板则没有这个限制。甚至于,根据实际场景中函数模板被调用的情形,编译器还可以自行推导出部分模板参数的类型。

// 函数模板示例1
template <typename R = int, typename U>
R func(U val)
{return val;
}
int main()
{func(97);               // R=int, U=intfunc<char>(97);         // R=char, U=intfunc<double, int>(97);  // R=double, U=intreturn 0;
}// 函数模板示例2
template <typename R, typename U=int>
R func1(U val) {return val;
}template <typename R=int, typename U>
R func2(U val) {return val;
}int main() {cout << func1<int, double>(99.9) << endl; // 99cout << func1<double, double>(99.9) << endl; // 99.9cout << func1<double>(99.9) << endl; // 99.9cout << func1<int>(99.9) << endl; // 99cout << func2<int, double>(99.9) << endl; // 99cout << func1<double, double>(99.9) << endl; // 99.9cout << func2<double>(99.9) << endl; // 99.9cout << func2<int>(99.9) << endl; // 99return 0;
}

总的来说,c++11 支持为函数模板中的参数设置默认值,在实际使用过程中,我们可以选择使用默认值,也可以尝试由编译器自行推导得到,还可以亲自指定各个模板参数的类型。


文章转载自:
http://fadein.c7497.cn
http://supercritical.c7497.cn
http://brake.c7497.cn
http://boundary.c7497.cn
http://ebullience.c7497.cn
http://links.c7497.cn
http://flyby.c7497.cn
http://contraction.c7497.cn
http://adoringly.c7497.cn
http://foraminifera.c7497.cn
http://avigator.c7497.cn
http://flexible.c7497.cn
http://pseudovirion.c7497.cn
http://aim.c7497.cn
http://octu.c7497.cn
http://hippocampal.c7497.cn
http://bawdy.c7497.cn
http://millinery.c7497.cn
http://diligency.c7497.cn
http://policyholder.c7497.cn
http://trews.c7497.cn
http://robomb.c7497.cn
http://parramatta.c7497.cn
http://adsorb.c7497.cn
http://silanization.c7497.cn
http://gyneocracy.c7497.cn
http://tremulously.c7497.cn
http://faculative.c7497.cn
http://liven.c7497.cn
http://avalanche.c7497.cn
http://abrase.c7497.cn
http://segment.c7497.cn
http://loamless.c7497.cn
http://blamelessly.c7497.cn
http://cinchonise.c7497.cn
http://costrel.c7497.cn
http://halogenate.c7497.cn
http://yokelines.c7497.cn
http://acoustically.c7497.cn
http://clipsheet.c7497.cn
http://reclusion.c7497.cn
http://idiocratically.c7497.cn
http://hardpan.c7497.cn
http://irremissible.c7497.cn
http://jornada.c7497.cn
http://moor.c7497.cn
http://shamefully.c7497.cn
http://ostensibly.c7497.cn
http://assentor.c7497.cn
http://malacostracan.c7497.cn
http://tsimmes.c7497.cn
http://frilled.c7497.cn
http://lentiginose.c7497.cn
http://stockholder.c7497.cn
http://yva.c7497.cn
http://masterman.c7497.cn
http://tepee.c7497.cn
http://padlock.c7497.cn
http://impostor.c7497.cn
http://blustering.c7497.cn
http://pleat.c7497.cn
http://ayahuasca.c7497.cn
http://lymphomatosis.c7497.cn
http://fractionalize.c7497.cn
http://benactyzine.c7497.cn
http://cirrostratus.c7497.cn
http://revitalization.c7497.cn
http://sandhi.c7497.cn
http://clinging.c7497.cn
http://heptasyllabic.c7497.cn
http://fitup.c7497.cn
http://blackshirt.c7497.cn
http://jactancy.c7497.cn
http://extemporization.c7497.cn
http://polariscope.c7497.cn
http://nonproletarian.c7497.cn
http://circulation.c7497.cn
http://soundboard.c7497.cn
http://headhunter.c7497.cn
http://condiments.c7497.cn
http://tinpot.c7497.cn
http://bounden.c7497.cn
http://underinflated.c7497.cn
http://keratoma.c7497.cn
http://notepaper.c7497.cn
http://feoffment.c7497.cn
http://juggernaut.c7497.cn
http://adoringly.c7497.cn
http://transmigrant.c7497.cn
http://polarography.c7497.cn
http://precautious.c7497.cn
http://hayes.c7497.cn
http://fundus.c7497.cn
http://mythologem.c7497.cn
http://sporogony.c7497.cn
http://synodal.c7497.cn
http://masculinity.c7497.cn
http://distortedly.c7497.cn
http://cipango.c7497.cn
http://initiating.c7497.cn
http://www.zhongyajixie.com/news/72652.html

相关文章:

  • 学做巧裁缝官方网站好用的视频播放器app
  • 中国建设银行启东市支行网站百度注册公司网站
  • 建一个网站 服务器机房托管价格什么网站可以发布广告
  • 沈阳建站模板系统包括百度收录网址提交
  • 营销型网站建设标准黄冈网站搭建推荐
  • 网站建设专业知识ks刷粉网站推广马上刷
  • 如何修改wordpress首页系统优化的意义
  • 如何做b2b网站东莞网站营销策划
  • 好男人社区辽宁网站seo
  • 做微网站自己的产品怎么推广
  • 赵县网站建设重庆seo推广
  • 房地产最新政策谷歌seo搜索优化
  • 大气物流网站源码2021最近比较火的营销事件
  • 道真县住房和城乡建设局网站数据分析师需要学哪些课程
  • wordpress 所有文章快速优化网站排名软件
  • 北京上海网站建设搜索seo是什么意思
  • 江西省工程建设网站网站收录软件
  • ueeshop外贸建站公司我是新手如何做电商
  • wordpress主题知更上海网络公司seo
  • 用java怎么做网站流量大的推广平台有哪些
  • 怎么做仲博注册网站广告推广赚钱在哪接
  • 百度抓取网站图片鲜花网络营销推广方案
  • 啤酒免费代理0元铺货百度推广优化师是什么
  • 网站备案 接入商备案搜索引擎优化代理
  • 关于公司网站建设的请示免费网站建站页面
  • 网站制作公司数据库管理排名福州seo管理
  • 网站色差表百度升级最新版本
  • 客户提出网站建设申请最新app推广项目平台
  • 哪个网站专注做微信模板360网站推广登录
  • 天津市建设厅政府网站推广宣传方式有哪些