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.
C++ 之 Direct and Copy Forms of Initialization的更多相关文章
- Lazy Initialization with Swift
Lazy initialization (also sometimes called lazy instantiation, or lazy loading) is a technique for d ...
- Lock-less and zero copy messaging scheme for telecommunication network applications
A computer-implemented system and method for a lock-less, zero data copy messaging mechanism in a mu ...
- C++ Core Guidelines
C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...
- Oracle Applications Multiple Organizations Access Control for Custom Code
档 ID 420787.1 White Paper Oracle Applications Multiple Organizations Access Control for Custom Code ...
- C++ essentials 之 explicit constructor
这篇博客的源起是我下面的一段代码 #include <bits/stdc++.h> using namespace std; int main(){ priority_queue<l ...
- 从 Bootstrap 2.x 版本升级到 3.0 版本
摘自http://v3.bootcss.com/migration/ Bootstrap 3 版本并不向后兼容 v2.x 版本.下面的章节是一份从 v2.x 版本升级到 v3.0 版本的通用指南.如需 ...
- h.264直接预测
直接预测是B帧上一种独有的预测方式,其中直接预测又分为两种模式: 时域直接模式(temporal direct).空域直接模式(spatial direct). 在分析这两种模式之前,有一个前提概念需 ...
- 多媒体封装格式----mkv
Matroska 开源多媒体容器标准.MKV属于其中的一部分.Matroska常见的有.MKV视频格式.MKA音频格式..MKS字幕格式..MK3D files (stereoscopic/3D vi ...
- [转]Publishing and Running ASP.NET Core Applications with IIS
本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...
随机推荐
- ubuntu mysql 更改IP导致mysql无法启动
bind-address = 127.0.0.1 => bind-address= 136.129.20.168 IP要这么改 这么改远程连不上,那么需要把这行整行注释掉,重启MYSQL,tel ...
- ModernUI教程:主题资源引用
已经完成的主题资源列表 提示:请关注Modern UI的开发工作,资源文件可能在演进版本中新增和删除. 资源列表可以去访问原文,原文可复制,该表未改动原文. 查看目录
- Mecanim动画模型规范
面数控制, 以三角面计算 不要超过4边的面 光滑组,法线 单位CM,单位比例 中心点 3DMax:Reset Transform Maya:Freeze Transformation 帧率:30帧 不 ...
- 深入浅出ASP.NET MVC5系列之一
前言 为避免看官乏味,本系列博客限定在较新的.Net framework 4.5.1,Asp.net MVC5,IIS 7.X集成模式. 对于微软应用层的技术.我向来不舍得花太多时间学习.但又由于公司 ...
- tornado和django的结合使用 tornado Server for django WSGI APP
#!/usr/bin/env python # Run this with # Serves by default at # http://localhost:8080/hello-tornado a ...
- 在iOS中实现类似安卓自动消失提示框
类方法: + (void)showMessage:(NSString *)message { // 获取window UIWindow *window = [UIApplication sharedA ...
- js中return的用法
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- webkit webApp 开发技术要点总结
如果你是一名前端er,又想在移动设备上开发出自己的应用,那怎么实现呢?幸好,webkit内核的浏览器能帮助我们完成这一切.接触 webkit webApp的开发已经有一段时间了,现把一些技巧分享给大家 ...
- C/C++中NULL的涵义
参考:百度知道NULL表示空指针,用于表示一个无效的指针,它的值为0(早期C语言的实现中可能有非0空指针,现在已经不用).对指针置NULL即标记指针无效,避免“野指针”的恶果.NULL在C/C++标准 ...
- C#-WinForm-跨窗体 构造函数传值 及应用—登录式窗口传值、如何关闭主页面时关闭应用程序、如何打开唯一窗口—★★★★★五星重量级
构造函数可以传任意类型的值,并可以同时传多个值 结构函数传值的初步应用--简单的登陆式界面 现在我有两个窗体Form3和Form4,如下,如何点击Form3中的按钮后,打开Form4并将Form3中的 ...