A tour of c++

本文探讨了C++中使用nullptr表示无对象引用的概念,深入解析了new操作符如何从自由存储区分配内存,以及对象独立于创建作用域的生命周期。讨论了联合体在节省空间方面的应用,并强调了其正确使用的必要性。最后,分析了异常处理的重要性,特别是在矢量类设计中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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’’).

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.

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值