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.

 

 

 

“a tour of c” 可以理解为C语言的一次巡回之旅。C语言是一种广泛应用于计算机硬件和软件开发的编程语言。它由贝尔实验室的丹尼斯·里奇于1972年开发,并在接下来的几年中逐渐流行起来。以下是关于C语言巡回之旅的一些重要内容: 首先,C语言具有简洁、高效的特点。它使用了一些基本的语法结构和关键字,使得程序代码更加简洁,易于理解和维护。同时,C语言的编译过程相对快速,生成的可执行文件也具有较高的执行效率。 其次,C语言具有广泛的应用领域。它被用于开发系统级软件,如操作系统和编译器,也被广泛应用于游戏开发、嵌入式系统、网络编程等领域。通过一次C语言的巡回之旅,可以深入了解C语言在不同领域中的应用和实践。 另外,C语言还具有丰富的库函数和标准函数供开发人员使用。这些库函数可以提供各种功能,如文件操作、字符串处理、内存管理等。通过学习和了解这些库函数,可以提高编程效率,并加快程序的开发速度。 最后,C语言也是学习其他高级编程语言的基础。许多其他编程语言,如C++、Java、Python等,都是在C语言基础上发展起来的。因此,通过一次C语言的巡回之旅,可以掌握一些基本的编程概念和思维方式,为学习其他编程语言打下坚实的基础。 总之,C语言巡回之旅是一个了解C语言的机会,通过深入学习和实践,可以了解C语言的特点、应用及其在计算机科学领域的重要性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值