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

手机电子商务网站建设策划书什么是核心关键词

手机电子商务网站建设策划书,什么是核心关键词,怎么做网站文章,深圳李日光建设公司一、decltype 关键字 1、介绍 decltype 是 C11 新增的一个用来推导表达式类型的关键字。和 auto 的功能一样,用来在编译时期进行自动类型推导。引入 decltype 是因为 auto 并不适用于所有的自动类型推导场景,在某些特殊情况下 auto 用起来很不方便&…

一、decltype 关键字

1、介绍

decltype 是 C++11 新增的一个用来推导表达式类型的关键字。和 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 一致

#include<string> 
#include<iostream>
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 为 int,x 被推导为 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 int&&int 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 的类型为 int&int 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

template<typename T>
class A
{
private :decltype(T.begin()) m_it;public:void func(T& container){m_it = container.begin();}
};int main()
{const vector<int> v;A<const vector<int>> obj;obj.func(v);return 0;
}

(5)使用decltype推导参数类型

可以在函数模板、类模板和 lambda 表达式中使用 decltype,从而推断类型或者声明类型。下面给出的示例代码展示了如何在 lambda 表达式中使用 decltype,推导出参数类型

#include <iostream>int 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://www.hkea.cn/news/900720/

相关文章:

  • 淄博有做网站的吗百度搜索排名怎么收费
  • wordpress页面添加自定义字段木卢seo教程
  • 长寿网站制作保定seo排名外包
  • 域名和网站一样吗电商运营推广怎么做
  • css个人简介网站怎么做b2b网站免费推广平台
  • 网站建设中企动力上海百度广告投诉电话客服24小时
  • 深圳靠谱的电商公司正版搜索引擎优化
  • 自己如何做团购网站腾讯云建站
  • 怀化招标网站磁力狗bt
  • 佛山网站建设服务公司培训机构查询网
  • 海尔集团电商网站建设考证培训机构
  • 动漫制作专业的高职实训室福州整站优化
  • 织梦商城网站模板免费下载怎么在网上做推广
  • asp做网站用什么写脚本温岭网络推广
  • 怎么建设外贸网站免费发seo外链平台
  • 郴州是几线城市武汉网站seo推广公司
  • 网站开发工程师求职信焊工培训内容
  • 铜陵公司做网站中国网站排名100
  • 我要建一个网站泰州百度公司代理商
  • php响应式网站模板vi设计公司
  • 随身wifi网站设置广告投放是做什么的
  • 中企动力做网站的优势网络销售平台有哪些软件
  • 网站建设的费用如何查看百度搜索指数
  • 自己做网站需要什么seo的基本步骤
  • 视频直播app开发网站南京最新消息今天
  • 溧阳手机网站哪里做万网域名注册官网查询
  • 网站维护收费推广产品吸引人的句子
  • 怎么用一个主机做多个网站许昌网络推广公司
  • 网站域名所有权郑州网站运营专业乐云seo
  • 桂园精品网站建设费用网站seo查询站长之家