首页 > 其他分享 >auto的重点

auto的重点

时间:2023-04-18 21:25:36浏览次数:32  
标签:const 常量 int auto 初始值 整型 重点

1.auto定义的变量必须有初始值

2.auto语句如果在一条语句中声明多个变量,所有变量的初始基本数据类型都必须相同:

1 auto sz =0,pi =3.14//错误:sz和pi的类型不一致

同样的如果在一条语句中给多个变量初始化时,初值必须时同一个类型(注意,非常量和常量是不同的类型)

1 int a=10;
2 const int b=20;
3 auto &n=i,*p=&b;//错误

3.如果引用作为初始值的时候,真正参与初始化的其实是引用对象的值。此时编译器以引用对象的类型作为auto的类型

4.当设置为一个类型为auto引用时。初始值中的顶层常量属性仍然保留

1 const int i=0;
2 auto &r=i;//则r变成了一个常量引用

5.当设置了一个auto类型的其他变量时,初始值中顶层const被忽略,底层const保留下来

1 int i=0;
2 const int ci=i;
3 auto d=&i;//&i代表的是一个指向整型的指针,因此d也是一个指向整型的指针
4 auto e=&ci;//&ci是一个指向整型常量的指针,是一个底层const,因此d也是一个指向整型常量的指针

如果想要保留顶层const必须明确指出

1 const int i=0;
2 const auto f=i;//不加const,f是一个非常量,加了之后就变成了一个常量

 

标签:const,常量,int,auto,初始值,整型,重点
From: https://www.cnblogs.com/Sandals-little/p/17331141.html

相关文章

  • 2023-4-18补缺for(auto i : v)遍历容器元素
    for(autoi:v)遍历容器元素1.auto2.auto&3.constauto&4.constautoC++11新增了一种循环:基于范围(range-based)的for循环。这简化了一种常见的循环任务:对数组(或容器类,如vector和array)的每个元素执行相同的操作,如下例所示:doubleprices[5]={4.99,10.99,6.87,6.47......
  • mvc5中使用autofac注册SignalR
    1.引用autofac.SignalR 2.Startup publicvoidConfiguration(IAppBuilderapp){DependencyConfig.RegisterDependencies(app);}3.RegisterDependencies//RegisteryourSignalRhubs.builder.RegisterHubs(Assembly.GetExecutingAssembly());var......
  • Autodesk Flame 2024 for mac(高级 3D 视觉效果) v2024激活版
    AutodeskFlame2024中文版提供用于快速、交互式3D视觉效果、精加工、合成、高级图形、颜色分级、整合、编辑和外观开发的工具。3D合成(动作)结合了传统2D合成的交互速度和强大的3D视觉效果。包括会话中艺术家的WYSIWYG预览。Flame2024中文版功能特色基于节点的合成(批处理......
  • Idea解决Could not autowire. No beans of ‘xxxx‘ type found的错误提示
    1.问题描述在Idea的spring工程里,经常会遇到Couldnotautowire.Nobeansof'xxxx'typefound的错误提示。(但程序的编译和运行都是没有问题的,有时候也有可能会报错,无法运行程序),这个错误提示并不会产生影响。但红色的错误提示看起来很不舒服。2.原因原因可能有两个,第一个是......
  • 论文解读《Automatically discovering and learning new visual categories with rank
    论文信息论文标题:Automaticallydiscoveringandlearningnewvisualcategorieswithrankingstatistics论文作者:K.Han, Sylvestre-AlviseRebuffi, SébastienEhrhardt, A.Vedaldi, AndrewZisserman论文来源:ICLR2020论文地址:download 论文代码:download视屏讲解:clic......
  • flomo 窗口置顶 - 通用方法 autohotkey
    需求开网页的时候需要记录一些东西想一直显示操作要安装https://www.autohotkey.com/创建个.ahk文件运行下快捷键是alt+小键盘8;置顶当前窗口!Numpad8::winset,AlwaysOnTop,,AReturn使用打开flomo为当前激活,然后按快捷键即可。----------------------------------......
  • 7 Skills To Become A Successful Automation Tester In 2019
    Withnew-ageprojectdevelopmentmethodologieslikeAgileandDevOpsslowlyreplacingtheold-agewaterfallmodel,thedemandfortestingisincreasingintheindustry. Testersarenowworkingtogetherwiththedevelopersandautomationtestingisvastly......
  • cnblogs raw markdown article auto crawler All In One
    cnblogsrawmarkdownarticleautocrawlerAllInOneurl获取rawmarkdownfile,类似GitHub/gistnext自动化翻页selenium???crontab定时任务自动化的备份cnblogs发表的原始文章资源,方便后续的blog批量迁移#!/usr/bin/envbash#coding:utf8#✅$(可执......
  • 第 14 章Linux 实操篇-进程管理(重点)
    第14章Linux实操篇-进程管理(重点)目录第14章Linux实操篇-进程管理(重点)14.1基本介绍14.2显示系统执行的进程14.2.1基本介绍14.2.2ps详解14.2.3应用实例14.1终止进程kill和killall14.3.1介绍:14.3.2基本语法14.3.3常用选项14.3.4最佳实践14.5服务(service)......
  • Could not autowire. No beans of BookDao' type found
    在做Spring或者SpringBoot项目时,在测试类中创建一个实体类属性并进行自动装配时,回报红:Couldnotautowire.NobeansofBookDao'typefound(只是环境的原因,不是错误) 直接Alt+Enter,将错误改成警告即可 ......