zoukankan      html  css  js  c++  java
  • 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(10, '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(10, '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(10, '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.

  • 相关阅读:
    一次Access注入
    偏移注入
    DHCP协议
    ARP协议、ARP欺骗
    bWAPP_HTML Injection
    上网行为管理&云计算
    两个文件上传/包含
    SQL报错注入
    如何建立git 远程仓库
    PHP实现异步调用方法研究
  • 原文地址:https://www.cnblogs.com/Patt/p/5791619.html
Copyright © 2011-2022 走看看