C

来源:互联网 发布:服务器数据实时备份 编辑:程序博客网 时间:2024/05/24 01:28

主题: static_cast和dynamic_cast的区别

 

static_cast转换类似于C/C++里面的强制类型转换。
dynamic_cast转换是根据基类派生类的原则进行转换,把一个派生类转换为基类使用这个转换。

主题: malloc, realloc, calloc的区别

ANSI C说明了三个用于存储空间动态分配的函数
(1) malloc   分配指定字节数的存储区。此存储区中的初始值不确定
(2) calloc   为指定长度的对象,分配能容纳其指定个数的存储空间。该空间中的每一位(bit)都初始化为0
(3) realloc  更改以前分配区的长度(增加或减少)。当增加长度时,可能需将以前分配区的内容移到另一个足够大的区域,而新增区域内的初始值则不确定

主题: what is the shallow and deep cpoying of objects in C++?

A shallow copy of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The pointer will be copied. but the memory it points to will not be copied -- the field in both the original object and the copy will then point to the same dynamically allocated memory, which is not usually what you want. The default copy constructor and assignment operator make shallow copies.

A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To make a deep copy, you must write a copy constructor and overload the assignment operator, otherwise the copy will point to the original, with disasterous consequences. 

主题: what is pure virtual function? what is its usage?

A pure virtual function is merely an interface and can be thought of as a way to enforce policy. A pure virtual function should be used when subclasses implement the same interface completely differently. For example, a persistence interface can have a write operation to store the state of an object. Yet, each class that implements this interface performs individual operations to store its state into a file:

原创粉丝点击