C + + Beginner's starter concept

Source: Internet
Author: User

    • The singleton design pattern guarantees that the object uniqueness of a class in memory.

If multiple programs read a configuration file, it is recommended that the configuration file be encapsulated as an object. Convenient operation of the data,
This configuration file object is required to be unique in memory.

    • The idea of ensuring object uniqueness 1. Do not allow other programs to create this class object.

                                                     2. Create a class object in this class.
                                                     3. Provide methods to allow other programs to obtain this object.

Steps
1. The creation of objects requires constructor initialization, as long as the constructors in this class are privatized, other programs can no longer create the class object;
2. Create an object of this class within a class.
3. Define a method that returns the object so that other programs can obtain the object by means of the method.

classsinger{Private: Singer () {}//privatisation constructor.         StaticSinger s =NewSinger ();//creates a private and static object of this class.  Public:         StaticSinger getinstance () {returnS }//defines a public and static method that returns the object. }
&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&

Code embodies
1. Privatization of the constructor function;
2. Create private and static objects of this class;
3. Define a public and static method to return the object.

                       &&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&

    • Understanding between two-dimensional arrays and pointers
1#include"stdio.h"2 intMain ()3 {4 inta[2][3]={{Ten, One, -}5,{ -, +, at}};6 7 8printf"%-10d The address of the two-dimensional array \ n", a); 9printf"%-10d Address of one-dimensional array \ n", a[0]); Tenprintf"%-10d Address of the first element of a one-dimensional array \ n", &a[0][0]);  Oneprintf"%-10d The value of the first element of a one-dimensional array \ n", a[0][0]); A  -printf"%-10d The address of the two-dimensional array \ n", a);  -printf"%-10d The address of the second element of a two-dimensional array \ n", A +1);//That is , the address of the one-dimensional array {20,21,23} the                                               //int Type 4 bytes, a+1 address minus A's address =12,12/4=3, that's the address of A[1] -printf"%-10d a[1] address \ n", a[1]);//address of the second element of a two-dimensional array -printf"%-10d Address of element 20 in one-dimensional array {20,21,23} \ n", &a[1][0]); -  +printf"%-10d The first element of the second line \ n", * (* (A +1)+0));//that is, the value of a[1][0] -  +printf"%-10d\n", **a);//A two-dimensional array is a pointer, *a gets the first address of a one-dimensional array, and **a gets the value based on the address . A}

            Summary 1. The element does not only refer to the number of shapes, but also to arrays. It's just a reference, the element of the two-dimensional array above is int ptr[3]; , is a one-dimensional array, the element of a one-dimensional array is an int tr;







C + + Rookie starter concept C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.