A tour of c++

I try to find out what i miss in c++

When we don’t hav e an object to point to or if we need to represent the notion of ‘‘no object available’’ (e.g., for an end of a list), we give the pointer the value nullptr (‘‘the null pointer’’).

A tour of c++

2.The new operator allocates memory from an area called the free store (also known as dynamic memory and heap).

Objects allocated on the free store are independent of the scope from which they are created and ‘‘live’’ until they are destroyed using the delete operator

My Word: the new operator often act as a new manager;deliver a continuous memory for the customer;

 

This is the basic technique for handling varying amounts of information in C++: a fixed-size handle referring to a variable amount of data ‘‘elsewhere’’ (e.g., on the free store allocated by new; §4.2.2). How to design and use such objects is the main topic of Chapter 4.

3

Unions

Maintaining the correspondence between a type field (here, t) and the type held in a union is errorprone. To avoid errors, one can encapsulate a union so that the correspondence between a type field and access to the union members is guaranteed. At the application level, abstractions relying on such tagged unions are common and useful, but use of ‘‘naked’’ unions is best minimized.

My Word: The use of Unions is based on saving the space (if two members are not used in the same time; especially with the enum ;

4

Eceptions

The writer of Vector doesn’t know what the user would like to hav e done in this case (the writer of Vector typically doesn’t even know in which program the vector will be running). •

The user of Vector cannot consistently detect the problem (if the user could, the out-of-range access wouldn’t happen in the first place).

 

To achieve that don’t overuse tr y-statements. The main technique for making error handling simple and systematic (called Resource Aquisition Is Initialization) is explained in §4.2.2.