C + + member initialization list

2010-06-29  来源:本站原创  分类:CPP  人气:156 

Excerpt: money can the "C + + Programming Tutorial"

A need to initialize the data member is an object of the situation;
Second, need to initialize const Modified class members;
Third, the members need to initialize the reference data;

class point
{
private:
    int x,y;
public:
    point(int m=0,int n=0):x(m),y(n)
    {
        x=m;
        y=n;
    }
    --
};

A need to initialize the data member is an object of the case;

class AAA
{
private:
    int aa;

public:// Normal initialization
    AAA(int i):aa(i){}

//public:// This is called an assignment
//    AAA(int i)
//    {
//        aa = i;
//    }
};

class BBB
{
private:
    AAA oo;

public:
    BBB(int i):oo(i) { }
};

Second, need to initialize const Modified class members;
Third, the members need to initialize the reference data;

As constant (const) can not be assigned;
Reference can not be re-assigned.

class Test
{
private:
    const int boy;
    int& girl;

public:
    Test(int i, int& j):boy(i), girl(j) { }
};
相关文章
  • C + + member initialization list 2010-06-29

    Excerpt: money can the "C + + Programming Tutorial" A need to initialize the data member is an object of the situation; Second, need to initialize const Modified class members; Third, the members need to initialize the reference data; class poin

  • static enum class member initialization in the constructor after 2010-06-06

    Enum initialization order and the general class of different public enum Color { RED("Red"), BLACK("Black"), WHITE("White"); private static int field = initStaticField(); Color(String name) { System.out.println("Construc

  • Member of C # class initialization order 2010-11-30

    First we look at the members of reference type initialization We look at one example class Program { static void Main (string [] args) { DriveB d = new DriveB (); } } class BaseA { static DisplayClass a = new DisplayClass ("base class static member i

  • JAVA / C + +: base class and derived class initialization order 2010-11-15

    Java: Base class member variables -> the base class constructor -> derived class member variable -> derived class constructor C + +: 1. If there are members of the class class, members of the class constructor is called first; 2. To create a deri

  • java object instance initialization sequence 2011-04-22

    How java object is initialized, the new file as a PrintClass.java (including class PrintClass and A and its subclass B), compile and run one of the main methods public class PrintClass { public static void main (String [] args) { new B (); } PrintCla

  • java objects in the creation process 2010-03-19

    Recent interview, there is a problem, java to use new to create an object, when the process in detail how the like. Was really being asked to live, and we have to do one of the principle of the development did not get to the bottom. Java programming

  • Common java programming errors 2010-03-23

    Repeat the definition of { int x=0; { int x=0; } } Method, parameter passing, with the object type, passing the object reference public static void Test_str(String str1){ { String s = str1; s = new String("str test"); } public static void main(S

  • Basic members of the default values 2010-03-23

    Basic member initialization default value Class creation

  • Summarize the essence of basic knowledge of JAVA 2010-04-13

    Summarize the essence of basic knowledge of JAVA 1, object initialization (1) non-static object initialization Created object, the object where the class members of all the data will first be initialized. Basic types: int type, initialized to 0. If t

  • ??___ C + + constructor Xiangjie 2010-04-14

    Some did not grasp the following constructor of meaning, stood first. . . . Original Address: http://ticktick.blog.51cto.com/823160/194307 c + + constructor of knowledge in a variety of c + + materials on the already introduced, but beginners usually

  • Elaborate on the constructor of the often cited 2010-04-25

    Elaborate on the constructor of the often quoted (2006-10-30 19:25) Constructor used to initialize the object. I believe that most understand. However: the constructor can not be inherited, the base class is first initialized, the base class initiali

  • Basic Java programming knowledge 2010-05-13

    1, object initialization (1) non-static initialization of objects created object, the object where the class members of all the data will first be initialized. Basic types: int type, initialized to 0. If the object: the object will be initialized in

  • Sixth class: object-oriented (5) - May 22, 2010 2010-07-04

    First, the internal class In some cases, we put a class inside another class definition, this definition within the class in other class is called inner classes (in some places, also known as nested classes), contains the internal class outside class

  • java-related vocabulary 2010-08-13

    ********************** <JAVA Programming terms English translation > ********************** abstract abstract abstract abstraction abstraction, abstract objects, abstract abstraction, abstract objects, abstract access access access access, visit acc

  • High quality C / C + + Programming Guide 2010-08-16

    Chapter 1 To prevent the header files are repeated references, should be used ifndef / define / endif preprocessing block structure generated Use # include <filename.h> reference standard library header files, use # include "filename.h" qu

  • C + + the static keyword 2010-08-28

    Static C + +, there are two uses: process-oriented program design static and object-oriented programming in the static. The former applies to ordinary variables and function, not related to class; latter shows the role of static in the class. First,

  • static meaning in different places 2010-09-18

    1. Source file using the static definition of function that is access: only in the source code can access the function, it corresponds to the function extern modified. (Note that the static function does not refer to a static class members) 2. Functi

  • Professional C + + Notes 2010-09-27

    Chapter 2 Designing Professional C + + Programs CPP two major design criteria: abstraction, reuse C hapter 3 Designing with Objects Well-designed API should make simple things simple, complex things possible. API design mainly of Wen Ti yes easy to u

  • C | C + + in a static global variables, static local variables, global variables, local variables, the difference between 2010-10-22

    There are two static usage: process-oriented programming, object-oriented design of static and the static. The former applies to ordinary variables and functions, does not involve classes; latter description of the role of static in the class. Static

  • Off-line usage of MFC's CTabCtrl 2010-10-24

    As to write a program on the tab, does not use MFC's CTabCtrl, to see how others write, found that the wording of extreme off-line OTL CListBoxDlg::CListBoxDlg() : CPropertyPage(CListBoxDlg::IDD) { //{{AFX_DATA_INIT(CListBoxDlg) // NOTE: the ClassWiz