C ++ primer 3rd edition Reading Notes-Article 1 C ++ Overview

Source: Internet
Author: User
In standard C ++, if the main () function does not explicitly provide the return statement, it returns 0 by default.

# The include indicator reads the content of a specified file in two formats:
If the file name is enclosed by Angle brackets <and>, it indicates that the file is a project or standard header file, and the search process checks the pre-defined directory.
If the file name is enclosed by a pair of quotation marks, it indicates that the file is the header file provided by the user. When searching for the file, it starts from the current file directory.

The Preprocessor name automatically defined by the compiler is __cplusplus ,__ stdc __,__ line __,__ file __,__ time __,__ date __. (The first two are not defined at the same time)

Two arrays are provided. We cannot use the value assignment operator to copy one array to another.

You can use one of the two versions of the new expression to dynamically allocate objects.

The first version is used to allocate a single object of a specific type, for example:
Int * pint = new int (1024 );
An int-type object without a name is assigned. The initial value of the object is 1024. Then, the expression returns the address of the object in the memory, and the address is used to initialize the pointer object. The only way pint can access the dynamically allocated memory is indirectly through the pointer.

The second version of the new expression is used to allocate arrays of specific types and dimensions, for example
Int * Pia = new int [4];
An array containing four integer elements is assigned. Unfortunately, we cannot explicitly specify an initial value for each element of the dynamically allocated array.

We can release the memory by using one of the two versions of the delete expression.
Delete expression of a single object: delete pint;
Delete expression in array format: Delete [] PIA;

The member functions defined in the class definition, such as size (), are automatically treated as inline functions.

Assume that the intarray class has the following constructor:
Explicit intarray (int sz = defaultarraysize); this is the default constructor. If a programmer provides a parameter, the value is passed to the constructor. For example, intarray array1 (1024); Pass Parameter 1024 to the constructor. On the other hand, if you do not specify the length, the constructor will use the defaultarraysize value (defaultarraysize is a static const member of the class)

Not all member functions can be automatically instantiated with the class template. Only member functions that are actually used by the program will be instantiated, this generally occurs in an independent stage of the program generation process.

The following declaration is made: Template <class elemtype> class array; the object defines array <int * &> PRI (1024); is incorrect. Because int * & is a reference, Initialization is required during definition, and the template does not provide initialization methods.

You can use the by-Value Method to pass built-in parameters, but the by const reference method should be used for general objects to reduce the overhead.

If the exception mechanism re-queries each function in the order that the function is called until the main () function still does not find the processing code, it will call the standard library function terminate (). By default, the terminate () function terminates the program.
A special catch clause that can handle all exceptions is as follows:
Catch (...)
{
// Handle all exceptions, although it cannot access the exception object
}

Namespace alias (namespace alias) allows an alternative, short, or more general name to be associated with an existing namespace. For example:
Namespace Lib = ibm_canada_laboratory; // provides a more general alias.
Aliases can also be used to encapsulate the actual namespace in use. In this case, we can change the namespace allocated to the alias to change the declaration set in use without changing the actual code used to access these declarations through the alias.

The Using Declaration provides a more fine-grained name visibility mechanism, allowing a single declaration in the middle of the name to be visible, so as to avoid introducing other unnecessary declarations. For example:
Using ibm_canada_laboratory: matrix; // only make the matrix visible

Different initialization methods of vector:
Vector <int> vec1 (size); // specify the capacity of the Vector
Vector <int> vec2 (size, value); // specify the capacity and initial value of the vector

Int Ia [4] = {0, 1, 1, 2 };
Vector <int> vec3 (IA, Ia + 4); // uses an array to initialize the vector.

Vector <int> vec4 (vec2); // copy constructor of Vector

Vector traversal (using begin () and end (), return the iterator pointing to the "Start" and "last" of the vector respectively ):
Vector <int> VEC (size );
Vector <int>: iterator iter = Vec. Begin ();
For (int ix = 0; iter! = Vec. End (); ++ ITER, ++ IX)
* Iter = IX;

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.