C ++ reading notes

xiaoxiao2021-03-06  41

Note: // The following is my own comment. Some content is referenced from the book "C programming language" book.

Chapter 1 Overview

Namespace is a method that encapsulates the library name. You can avoid naming conflicts with your application.

Structured syntax defined by variables: int num_tries (0); // Used to handle multi-value initialization examples: Complex purei (0, 7);

C supports three types of floating point categories, Float single-precision, Double double precision, long double expansion accuracy

The Template Class mechanism makes the programmer until the real data type is determined when using the template class.

When the file path is represented by a constant string under Windows, the anti-slope character must be indicated by a "escape sequence".

C built-in bool type uses true / false to indicate true holiday.

The object initialization value is not allowed to change.

% More.

Arrays, vectors (vector)

The size of Array must be a constant expression.

Array initialization element interval ","

Vector Object must be included in the Vector header file, define how to:

Const int seq_size = 18;

#include

Vector Pell_Seq (SEQ_SIZE);

Other usage vector and array are the same.

Iterative (traversal, item)

Initialization of VECTOR:

1, initialized one by one;

2, use the initialized array as the initial value of the vector, Vector ELEM_SEQ (an array of initialized arrays, array name size);

Vector knows your size. ELM_SEQ.size () represents the size of the Vector.

Vector is a simple object that can be assigned (THE C Programming Language (Special Edition).

& Multiple Use.

A pointer that does not point to any object, its internal address is 0.

Pointer to vector : vector * PV = 0;

Randomize the function rand () and srand () of the standard function library CSTDLIB.

SRAND (size); // parameter is the seed generated by the random number (SEED)

Rand ();

FSTREAM file operation

OFSTREAM, if the file does not exist as an output, if there is, the output is turned on, and the data existing in the file will be lost.

If you don't want to discard the original content, turn on the append mode, iOS_BASE :: App

The file is likely to open failed, and it must be determined before the write operation is successful.

IF (! outfile) // file definition file pointer

or

IF (Outfile.Fail ()) // C programming tutorial, money energy, Tsinghua University Press

The controller performs some operations on the iostream, such as: Endl will insert a wrap character and clear the contents of the output buffer

Other Controllers: NEX, OCT, SetPrecision (n) // Setting Accuracy

File repositioning SKEEG ()

Chapter 2, the programming style

EXIT () needs to include a cstdlib header file

Trust is not a good engineering principle

The parameter name can be omitted in the function declaration, leaving only the function type.

The PEFERENCE pass value (BY value) debugger can be added to the print statement to track the logic of the control process and display the status of the object.

When we call a function, a special area will be established in memory, called "Program Stack"

The object represented is not allowed to change.

Quote is just a alias of the variable.

If you add a Const line in row, the content will not be changed.

Use of New and Delete. Used to allocate allocation of HEAP MEMORY in the heap.

The reference pass value cannot be set to zero.

When the second parameter is set to the pointer, and after the default value is set, it can be called in a single parameter when invoked.

Enter the debug information into the file, let Cout become the default ostream parameters: Ostream & OS = COUT

All parameters on the right side of the default parameter must also have the default parameters, otherwise it is illegal.

The default value can only be specified once, and can be in the function declaration, but can not be specified in two places.

Inline function, declare the function of Inline, the compiler expands the function content at each function call point. The general inline function is generally placed in the header file. The inline function is just a request.

Provides overloaded functions, parameter tables (different types of parameters, may also be different) of two or more functions, which can have the same function name. However, the compiler cannot distinguish between two functions of the same name according to the return value type.

Template function (Template function), Template Keyword TypeName indicates that ELEMTYPE is a temporary placement, and ELEMTYPE is any name.

The definition of the function can only have one, but the declaration of the function can have many copies.

The definition of the Inline function can be multiple copies, in order to extend the content of the Inline function.

Chapter 3 generic programming style

To use generic algorithms to include Algorithm header files

Standard Template Library (STL) is mainly composed of two components: one is a container (Container) including VECTOR, LIST, SET, MAP, etc. Another component is to operate the so-called generic algorithm of these containers, including Find (), Sort (), Replace (), Marge (), and more.

Vector and LIST are sequence containers. Map and set are associated containers.

The so-called generic algorithm provides many operational behaviors that can be implemented on containers and array types. They have nothing to do with the elements they have to operate.

The array is to participate, and only the address of the first element is incorporated. Equivalent to a pointer to the first address of the array. We can define an element to indicate the end point of the array (the next address of the last element of the array), we call "sentry"

Wild pointer (Iterators)

Each standard container provides a begin () operation function pointing to the first element, another end () operation function points to the next position of the last element, and they return an item. The container provides INSERT () to install an element to provide ERASE () to delete an element.

Frequency definition form iTarator iTer;

Vector :: item ore = s.begin ();

All containers are common operation Equality (==) and INEQUALITY (! =)

Assignment (=) replication

Empty () Container returns True when there is no element

Size () number of elements currently included in the conveyor

Clear () Deletes all elements

INSERT ()

Sequence container Deque

Define the way sequence container objects

1. Generate an empty container:

List SLIST;

Vector ivec;

2, generate a specific size container:

List ILIST (1024);

3, generate a specific size container and specify the initial value for each element:

List SLIST (16, "Content");

4. Generate containers through a pair of ITERATORS:

INT IA [8] = {1, 2, 3, 4, 5, 6, 7, 8};

Vector FIB (IA, IA 8);

5. A new container is generated according to a container.

List SLIST;

//content

List Slist2 (LIST);

Provide two special operation functions, allowing an insertion and deletion operation at the end of the container: Push_bach () and POP_BACK ().

In addition, List and Deque (but not included) also provide push_front (), and pop_front.

The THIS pointer is used to address its caller in Meber Function. The internal operation process is that the compiler automatically adds the THIS pointer to the parameter table of each MEMBER FUNCTION. Due to internal code conversion, Tr1.copy (TR2) will become COPY (& TR1, TR2);

In Member functions, the THIS pointer allows us to take everything of its caller.

The object returned to the call is as long as the simple privilege can. RETURN * THIS;

Determines if the two objects are the same, use this! = & Rhs

Static class members, Static Data Members are used to represent the only one-shared Members. He can be accessed in the same type of objects. Data members who are declared for Static are a class of special shared data members regardless of this class object being defined. There is only one static data member in the program.

// Mego, all objects will call the memory space of the same class member. Not a separate memory space.

// General method of the initial value in the class: 1, = Direct assignment 2, function assignment method AA (67); 3, add: After the above-described copying is performed.

Like Const Static Int Data Members, you can understand the initial value for the declaration.

The Members Function can only be declared as static without accessing any Non-Static Members, and the declaration is the keyword Static before the declaration.

Operator overload Operator, for example: inline book operator == (const triangular & rhs) const {return_index == rhs._index;}

The operator overload must have at least one parameter is a Class type.

Quote is a pointer // C Primer3esc with a pointed syntax

// Function overload [] implementation.

/ / # include

// using namespace std;

// int & infaRray :: Operator [] (int index) {

// assert (index> = 0 && index

// Return IA [INDEX];

// (C Primer3ESC implementation) Although the C built-in array supports the mechanism of the container, it does not support the semantics of the container abstraction.

In standard C , array class is part of the C standard library called vector.

The VECTOR class provides a pair of begin () / * starts * / and end () / * end 1 * /

The parameter in the generic algorithm should use the start address plus the offset.

Most of the generic algorithms are included in the header file algorithm

C provides a set of operators to support bit operations, as well as a bit set (BitSet) container type, which can be used to declare objects containing bit collection.

Wide character type Wchar_t style: l'a '

C supports two forms of initialization

The first form is an explicit speaking form using an assignment operator

INT IVAL = 1024; String Project = "Fantasia 2000";

In the implicit form, the initial value is placed in parentheses.

INT IVAL (1024); String Project ("Fantasia 2001");

The address of the Const object can only assign a pointer to the Const object. However, the pointer to the Const object can be assigned an address of a non-Const object.

The reference can no longer point to other objects once it is defined.

In particular, the hierarchy of the abnormal class can be used to group an exception, so that a processing code can process an error only on the appropriate detail hierarchy.

A NameSpace refers to a named Scope. NameSpace is used to divide the relevant statement together, separated by the unrelated code parts.

C specifies: Inside a particular Namespace, even if it does not do explicit limits, it is also possible to be valid for the object name contained in this NameSpace.

转载请注明原文地址:https://www.9cbs.com/read-68438.html

New Post(0)