C++ 之 Direct and Copy Forms of Initialization
Extraction from C++ Primer 5th. Editioin 3.2.1
C++ has several different forms of initialization, we should understand how these forms differ from one aother.
When we initialize a variable using =, we are asking the compiler to copy initialize the object by copying the initializer on the right-hand side into the object being created.
Ohterwise when we omit the =, we use direct intialization.When we have a single intializer, we use either the direct or copy form of intialization. When we intialize a variable from more than one value, such as:
string s4(, 'c');
we must use the direct form of initialization.
when we want to use several values, we can indirectly use the copy form of intialization be explicitly creating a (temporary) object to copy:
string s8=string(, 'c'); //copy initialization
The intializer of s8——string(10, 'c')——creates a string of the given size and character value and then copies that value into s8. it is as if we had written
string temp(, 'c');
string s8=temp;
Although the used to intialize s8 is legal, it is less readable and offers no compensating advantage over the way we intilize s4.
最新文章
- 关于在Linux64位下安装xampp
- learn mips
- AngularJs--angular-pagination可复用的分页指令
- vbscript input select 添加个option根据value值到指定位置--相当于排序
- Servlet下载文件和http响应
- Java多线程系列--“JUC线程池”05之 线程池原理(四)
- MVC认知路【点点滴滴支离破碎】【四】----捆绑和缩小(BundleConfig.RegisterBundles)
- Shell 脚本 ,, 根据进程号退出 从而关机
- MVC中return File(byte[],";image/jpeg";)输入图片不清晰
- java专业规划(转载)
- 百度富文本编辑器UEditor1.3上传图片附件等
- 6.解决AXIOS的跨域问题
- python键盘读入的input方法
- MassTransit 实现发布/订阅
- 第十四章——循环神经网络(Recurrent Neural Networks)(第一部分)
- shell 重定向 2>;&;1 2>;/dev/null 理解笔记
- Python中的xxx == xx是否等价于xxx is xxx
- 概率图模型 基于R语言 这本书中的第一个R语言程序
- VUE 打包后关于 -webkit-box-orient: vertical; 消失,导致多行溢出不管用问题
- DES加解密 cbc模式 的简单讲解 &;&; C++用openssl库来实现的注意事项