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

手机网站建设视频教程、支付宝网站开发流程

手机网站建设视频教程、,支付宝网站开发流程,公司域名申请流程,wordpress添加模板后台显示一、decltype 关键字 1、介绍 decltype 是 C11 新增的一个用来推导表达式类型的关键字。和 auto 的功能一样#xff0c;用来在编译时期进行自动类型推导。引入 decltype 是因为 auto 并不适用于所有的自动类型推导场景#xff0c;在某些特殊情况下 auto 用起来很不方便…一、decltype 关键字 1、介绍 decltype 是 C11 新增的一个用来推导表达式类型的关键字。和 auto 的功能一样用来在编译时期进行自动类型推导。引入 decltype 是因为 auto 并不适用于所有的自动类型推导场景在某些特殊情况下 auto 用起来很不方便甚至压根无法使用。 auto varName value; decltype(exp) varName value;auto与decltype在形式上的区别如下 auto 根据 右边的初始值推导出变量的类型decltype 根据 exp 表达式推导出变量的类型跟 右边的 value 没有关系auto 要求变量必须初始化因为 auto 是根据变量的初始值来推导变量类型的如果不初始化变量的类型也就无法推导。而 decltype 不要求因此可以写成如下形式 decltype(exp) varName;2、推导规则 1如果 exp 是一个不被括号()包围的表达式或者是一个类成员访问表达式或者是一个单独的变量decltype(exp) 的类型和 exp 一致 #includestring #includeiostream using namespace std;class A { public:static int total;string name;int age;float scores; }int A::total 0;int main() {int n 0;const int r n;A a;decltype(n) x n; // n 为 intx 被推导为 intdecltype(r) y n; // r 为 const int y 被推导为 const int decltype(A::total) z 0; // total 是类 A 的一个 int 类型的成员变量z 被推导为 intdecltype(A.name) url www.baidu.com; // url 为 string 类型return 0; } 2如果 exp 是函数调用则 decltype(exp) 的类型就和函数返回值的类型一致 int func1(int, char); // 函数返回值为 int int func2(void); // 函数返回值为 int int func3(double); // 函数返回值为 intconst int func4(int, int, int); // 函数返回值为 const int const int func5(void); // 函数返回值为 const intint n 50; decltype(func1(100,A)) a n; // a 的类型为 int decltype(func2()) b 0; // b 的类型为 int decltype(func3(10.5)) c 0; // c 的类型为 intdecltype(func4(1,2,3)) x n; // x 的类型为 const int decltype(func5()) y 0; // y 的类型为 const int 3如果 exp 是一个左值或被括号()包围decltype(exp) 的类型就是 exp 的引用假设 exp 的类型为 T则 decltype(exp) 的类型为 T class A { public:int x; }int main() {const A obj;decltype(obj.x) a 0; // a 的类型为 intdecltype((obj.x)) b a; // b 的类型为 intint n 0, m 0;decltype(m n) c 0; // n m 得到一个右值c 的类型为 intdecltype(n n m) d c; // n n m 得到一个左值d 的类型为 int return 0; } 4类的静态成员可以使用 auto 对于类的非静态成员无法使用 auto如果想推导类的非静态成员的类型只能使用 decltype templatetypename T class A { private :decltype(T.begin()) m_it;public:void func(T container){m_it container.begin();} };int main() {const vectorint v;Aconst vectorint obj;obj.func(v);return 0; } 5使用decltype推导参数类型 可以在函数模板、类模板和 lambda 表达式中使用 decltype从而推断类型或者声明类型。下面给出的示例代码展示了如何在 lambda 表达式中使用 decltype推导出参数类型 #include iostreamint main() {int x 42;auto f [](decltype(x) val) { val 1; };f(x);std::cout x: x std::endl; // x: 43return 0; } 在这个例子中定义了一个 lambda 表达式 f它的参数使用了 decltype 推断出参数类型为 int。由于在 lambda 表达式中使用的变量必须是可见的因此在 lambda 表达式前面的捕获列表中使用了 []以让 lambda 表达式捕获 x。最后调用 lambda 表达式 f并将变量 x 作为参数传递给它从而使 x 的值被加 1。
http://wiki.neutronadmin.com/news/76102/

相关文章:

  • 与铁路建设相关的网站软件开发专业需要学什么
  • 免费素材网站哪个最好门户网站主要包括哪些模块
  • 网站由哪几部分组成wordpress与phpstudy
  • 怎样建网站才赚钱网页升级紧急通知俏佳人
  • 专做袜子的网站电脑wordpress
  • 门户网站为什么衰落网游推广员
  • 黄埔移动网站建设商贸有限公司的经营范围
  • 专业网站建设机构免费的行情软件app网站
  • 提高网站订单转化率网站上可以做直播吗
  • 专业的网页设计和网站制作公司岳池县网站建设
  • 成都企业网站维护网站建设必须注意的事项
  • 网站logo如何修改中信建设有限责任公司是央企吗
  • 个人网站做商城会怎样电子商务网站建设李洪心课后答案
  • 信息图表设计网站phpcms v9网站模板
  • 做物流网站有哪些功能教做幼儿菜谱菜的网站
  • 网站设计培训学校最简单的网页
  • 纯html网站wordpress有中文官方版
  • 订阅号可以做网站链接吗织梦可以做大型网站吗
  • 网站设计建设代理机构网站建设公司哪家好
  • 工程网站开发微信营销模式有
  • ip反查工具网站网站建设晋icp备
  • 网站建设电销手表网站欧米茄报价
  • 网站金融模版wordpress外贸网站增加个博客栏
  • 做百度推广去些网站加客户app开发公司历程概述
  • 做网站要不要学ps在线3d设计家官网
  • 成都网站建设与网站制作wordpress 主题 后门
  • 网站开发管理招聘湖州猪八戒做网站
  • 公司专业网站建设vs做的网站图片显示不了
  • 免费创建网站培训类 网站后台
  • php做商品网站动漫网站html