`
gaofen100
  • 浏览: 1187517 次
文章分类
社区版块
存档分类
最新评论

C++对象模型 ch5 构造 析构 拷贝语义学

 
阅读更多

1. 关于拷贝operator

While poking around cfront recently, I noticed that when generating the copy operator, it does not condition the copy by a guard of the form

if ( this == &rhs ) return *this;
As a result, it applies redundant copying for expressions such as

Line *p1 = &a;
Line *p2 = &a;
*p1 = *p2;

2.构造函数做了哪些动作?

The general algorithm of constructor execution is as follows:

1) Within the derived class constructor, all virtual base class and then immediate base class constructors are invoked.

2) That done, the object's vptr(s) are initialized to address the associated virtual table(s).

3) The member initialization list, if present, is expanded within the body of the constructor. This must be done after the vptr is set in case a virtual member function is called.

4) The explicit user-supplied code is executed.

3. 在构造函数成员初始化列表中调用虚函数是不是安全的?
Is it safe to invoke a virtual function of the class within its constructor's member initialization list? Physically, it is always safe when the function is applied to the initialization of a data member of the class. This is because, as we've seen, the vptr is guaranteed to have been set by the compiler prior to the expansion of the member initialization list. It may not be semantically safe, however, because the function itself may depend on members that are not yet initialized. It is not an idiom I recommend. However, from the point of view of the integrity of the vptr, it is a safe operation.

4. 编译器何时生成一个析构函数?

If a destructor is not defined by a class, the compiler synthesizes one only if the class contains either a member or base class with a destructor. Otherwise, the destructor is considered to be trivial and is therefore neither synthesized nor invoked in practice.

分享到:
评论

相关推荐

    C++对象模型总结

    第5章 构造、析构、拷贝语意学 第6章 执行期语意学 第7章 站在对象模型的尖端 第8章 C++对象模型总结 8.1 C++对象模型 8.2 单继承 8.2.1 无重写的单继承 8.2.2 有重写的单继承 8.3 多继承 8.4 虚拟继承 8.4.1 简单虚...

    C++对象在堆栈区的析构

    C++对象在堆栈区的析构 一般人别乱下~我自己需要的。

    深度探索c++对象模型(2012版本)

    深度探索c++对象模型(2012版本)

    C++类对象的拷贝构造函数

    C++类对象的拷贝构造函数 C++类对象的拷贝构造函数 C++类对象的拷贝构造函数 C++类对象的拷贝构造函数 C++类对象的拷贝构造函数 C++类对象的拷贝构造函数

    深度探索C++对象模型 PDF

    深度探索C++对象模型 C++程序员必看编程书籍

    深度探索C++对象模型(清晰版).pdf

    书中涵盖了C++对象模型的语意暗示,并指出这个模型是如何影响你的程序的。 对于C++底层机制感兴趣的读者,这必然是一本让你大呼过瘾的绝妙好书。如果你是一位C++程序员,渴望对于底层知识获得一个完整的了解,那么...

    深度探索C++对象模型.pdf +清晰+完整+书签

    深度探索C++对象模型

    深度探索C++对象模型

    深度探索C++对象模型 第0章 导读(译者的话) 第1章 关于对象(Object Lessons) 加上封装后的布局成本(Layout Costs for Adding Encapsulation) 1.1 C++模式模式(The C++ Object Model) 简单对象模型(A Simple...

    深度探索C++对象模型 PDF中文清晰版

    《深度探索C++对象模型》专注于C++面向对象程序设计的底层机制,包括结构式语意、临时性对象的生成、封装、继承,以及虚拟——虚拟函数和虚拟继承。这本书让你知道:一旦你能够了解底层实现模型,你的程序代码将获得...

    深度探索C++对象模型_中英

    深度探索C++对象模型_中英 深度探索C++对象模型_中英 深度探索C++对象模型_中英

    C++对象在堆栈区的析构 - 好好理解堆栈

    作为一个C++程序员,区别于其他面向对象语言其中最敏感的就是对new(malloc)和delete(free)这两个关键字了.。。。。。

    深入探索c++对象模型 设计模式c++ pdf

    深入探索c++对象模型 设计模式c++ pdf 深入探索c++对象模型 设计模式c++ pdf 深入探索c++对象模型 设计模式c++ pdf 深入探索c++对象模型 pdf 设计模式c++ pdf

    深度探索C++对象模型 PDF中文清晰版.zip

    深度探索C++对象模型 PDF中文清晰版.zip深度探索C++对象模型 PDF中文清晰版.zip深度探索C++对象模型 PDF中文清晰版.zip深度探索C++对象模型 PDF中文清晰版.zip深度探索C++对象模型 PDF中文清晰版.zip深度探索C++对象...

    深度探索C++对象模型 超高清pdf

    深度探索C++对象模型 超高清

    深度探索C++对象模型 中文pdf 英文chm

    深度探索C++对象模型 中文图片影印版pdf,比较清晰,不是那种模糊的版本,和文字版差别不大 英文清晰文字版chm 第一代C++编译器开发主管所写。如果你想成为真正的C++高手,看这本书,他为你讲述了编译器在处理各种...

    包含构造函数和析构函数的C++程序

    本程序包含构造函数和析构函数,可以把构造函数和析构函数的作用区分开

    深度探索模C++对象模型PDF

    第5章 构造、解构、拷贝 语意学(Semantics of Construction,Destruction,and Copy) 纯虚拟函数的存在(Presence of a Pure Virtual Function) 虚拟规格的存在(Presence of a Virtual Specification) 虚拟规格...

Global site tag (gtag.js) - Google Analytics