青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

asm, c, c++ are my all
-- Core In Computer
posts - 139,  comments - 123,  trackbacks - 0

/********************************************\
|????歡迎轉載, 但請保留作者姓名和原文鏈接, 祝您進步并共勉!???? |
\********************************************/


Chapter 2. The Semantics of Constructors
----------------------------------------
2.1 Default Constructor Construction

作者: Jerry Cat
時間: 2006/04/27
鏈接:?http://www.shnenglu.com/jerysun0818/archive/2006/04/28/6407.html

========================================
Global objects are guaranteed to have their associated memory "zeroed out" at program start-up. Local objects allocated on the program stack and heap objects allocated on the free-store do not have their associated memory zeroed out; rather, the memory retains the arbitrary bit pattern of its previous use.

If there is no user-declared constructor for class X, a default constructor is implicitly declared…. A constructor is trivial(瑣碎, 微不足道, 啥也不干) if it is an implicitly declared default constructor….

1). Member Class Object with Default Constructor:
If a class without any constructors contains a member object of a class with a default constructor, the implicit default constructor of the class is nontrivial and the compiler needs to synthesize a default constructor for the containing class. This synthesis, however, takes place only if the constructor actually needs to be invoked.

An interesting question, then: Given the separate compilation model of C++, how does the compiler prevent synthesizing multiple default constructors, for example, one for file A.C and a second for file B.C? In practice, this is solved by having the synthesized default constructor, copy constructor, destructor, and/or assignment copy operator defined as inline. An inline function has static linkage and is therefore not visible outside the file within which it is synthesized. If the function is too complex to be inlined by the implementation, an explicit non-inline static instance is synthesized.

For example, in the following code fragment, the compiler synthesizes a default constructor for class Bar:

class Foo { public: Foo(), Foo( int ) ... };

class Bar { public: Foo foo; char *str; };

void foo_bar() {
?? Bar bar; // Bar::foo must be initialized here
?? if ( str ) { } ...
}
The synthesized default constructor contains the code necessary to invoke the class Foo default constructor on the member object Bar::foo, but it does not generate any code to initialize Bar::str. Initialization of Bar::foo is the compiler's responsibility; initialization of Bar::str is the programmer's. The synthesized default constructor might look as follows:

____To simplify our discussion, these examples ignore the insertion of the implicit this pointer.
// possible synthesis of Bar default constructor
// invoke Foo default constructor for member foo
inline Bar::Bar()
{
?? foo.Foo::Foo(); // Pseudo C++ Code
}
Again, note that the synthesized default constructor meets only the needs of the implementation, not the needs of the program.

What happens if there are multiple class member objects requiring constructor initialization? The language requires that the constructors be invoked in the order of member declaration within the class. This is accomplished by the compiler. It inserts code within each constructor, invoking the associated default constructors for each member in the order of member declaration. This code is inserted just prior to the explicitly supplied user code. For example, say we have the following three classes:

class Dopey?? { public: Dopey(); ... };
class Sneezy? { public: Sneezy( int ); Sneezy(); ... };
class Bashful { public: Bashful() ... };
and a containing class Snow_White:

class Snow_White {
public:
?? Dopey dopey;
?? Sneezy sneezy;
?? Bashful bashful;
?? // ...
private:
?? int mumble;
};
If Snow_White does not define a default constructor, a nontrivial default constructor is synthesized that invokes the three default constructors of Dopey, Sneezy, and Bashful in that order. If, on the other hand, Snow_White defines the following default constructor:

// programmer coded default constructor
Snow_White::Snow_White() : sneezy( 1024 )
{
?? mumble = 2048;
}
it is augmented as follows:

// Compiler augmented default constructor
// Pseudo C++ Code
Snow_White::Snow_White()
{
?? // insertion of member class object constructor invocations
?? dopey.Dopey::Dopey();
?? sneezy.Sneezy::Sneezy( 1024 );
?? bashful.Bashful::Bashful();

?? // explicit user code
?? mumble = 2048;
}

2). Base Class with Default Constructor:
Similarly, if a class without any constructors is derived from a base class containing a default constructor, the default constructor for the derived class is considered nontrivial and so needs to be synthesized. The synthesized default constructor of the derived class invokes the default constructor of each of its immediate base classes in the order of their declaration. To a subsequently derived class, the synthesized constructor appears no different than that of an explicitly provided default constructor.

What if the designer provides multiple constructors but no default constructor? The compiler augments each constructor with the code necessary to invoke all required default constructors. However, it does not synthesize a default constructor because of the presence of the other user-supplied constructors. If member class objects with default constructors are also present, these default constructors are also invoked梐fter the invocation of all base class constructors.

3). Class with a Virtual Function:
There are two additional cases in which a synthesized default constructor is needed:

(1). The class either declares (or inherits) a virtual function
(2). The class is derived from an inheritance chain in which one or more base classes are virtual

In both cases, in the absence of any declared constructors, implementation bookkeeping necessitates the synthesis of a default constructor. For example, given the following code fragment:

class Widget {
public:
?? virtual void flip() = 0;
?? // ...
};

void flip( const Widget& widget ) { widget.flip(); }

// presuming Bell and Whistle are derived from Widget
void foo() {
?? Bell b;? Whistle w;
?? flip( b );
?? flip( w );
}
the following two class "augmentations" occur during compilation:

(3). A virtual function table (referred to as the class vtbl in the original cfront implementation) is generated and populated with the addresses of the active virtual functions for that class.
(4). Within each class object, an additional pointer member (the vptr) is synthesized to hold the address of the associated class vtbl.

In addition, the virtual invocation of widget.flip() is rewritten to make use of widget's vptr and flip()'s entry into the associated vtbl:

?? // simplified transformation of virtual invocation:
widget.flip()
?? ( * widget.vptr[ 1 ] ) ( &widget )
where:

____1 represents flip()'s fixed index into the virtual table, and

____&widget represents the this pointer to be passed to the particular invocation of flip().

For this mechanism to work, the compiler must initialize the vptr of each Widget object (or the object of a class derived from Widget) with the address of the appropriate virtual table. For each constructor the class defines, the compiler inserts code that does just that (this is illustrated in Section 5.2). In classes that do not declare any constructors, the compiler synthesizes a default constructor in order to correctly initialize the vptr of each class object.

4). Class with a Virtual Base Class:
Virtual base class implementations vary widely across compilers. However, what is common to each implementation is the need to make the virtual base class location within each derived class object available at runtime. For example, in the following program fragment:

class X { public: int i; };
class A : public virtual X?? { public: int j; };
class B : public virtual X?? { public: double d; };
class C : public A, public B { public: int k; };
// cannot resolve location of pa->X::i at compile-time
void foo( const A* pa ) { pa->i = 1024; }

main() {
?? foo( new A );
?? foo( new C );
?? // ...
}
the compiler cannot fix the physical offset of X::i accessed through pa within foo(), since the actual type of pa can vary with each of foo()'s invocations. Rather, the compiler must transform the code doing the access so that the resolution of X::i can be delayed until runtime. In the original cfront implementation, for example, this is accomplished by inserting a pointer to each of the virtual base classes within the derived class object. All reference and pointer access of a virtual base class is achieved through the associated pointer. In our example, foo() might be rewritten as follows under this implementation strategy:

// possible compiler transformation
void foo( const A* pa ) { pa->__vbcX->i = 1024; }
where?__vbcX represents the compiler-generated pointer to the virtual base class X.

As you've no doubt guessed by now, the initialization of __vbcX (or whatever implementation mechanism is used) is accomplished during the construction of the class object. For each constructor the class defines, the compiler inserts code that permits runtime access of each virtual base class. In classes that do not declare any constructors, the compiler needs to synthesize a default constructor.

2.1 小結:
=-=-=-=-=
Programmers new to C++ often have two
common misunderstandings:

? 1. That a default constructor is synthesized for every class that does not define one
? 2. That the compiler-synthesized default constructor provides explicit default initializers for each data member declared within the class

posted on 2006-04-28 03:00 Jerry Cat 閱讀(1072) 評論(3)  編輯 收藏 引用

FeedBack:
# re: C++對象模型(4) - Default Constructor Construction
2006-04-28 18:39 | dfdffddffdfd
你些的我看不懂,小樣,我8級的也看不懂~~~~請你編個中文版的解說。
知道不??????????????????  回復  更多評論
  
# re: C++對象模型(4) - Default Constructor Construction
2006-04-28 18:51 | 婀娜
彩運500萬福彩3D110期預測
膽碼:34

復式:復式:123/357/014
喜歡合買的朋友,可以加我QQ448967360聊聊!
彩運500萬http://www.cy500.com
  回復  更多評論
  
# re: C++對象模型(4) - Default Constructor Construction
2006-04-29 01:04 | Jerry Cat
dfdffddffdfd, 小樣不小樣免了吧:) 8級有用么? 你不是學計算機的吧? 這非我寫, 乃C++大師Stanley所寫, 國內學校100級英語也不行呀! 不是對你有任何看法, 大家一起努力吧! 只不過想到外企拿高薪并且35歲后不失業, 不能心浮, 要靜心好好地去學!

--------------------------------------------------

(附: 請在小弟處只談asm, c, C++, 別的免談, 這句送給哪個買啥鳥彩票的朋友!)  回復  更多評論
  

只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理



<2006年4月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用鏈接

留言簿(7)

隨筆檔案

最新隨筆

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            av成人老司机| 久久九九精品99国产精品| 亚洲国内自拍| 欧美超级免费视 在线| 亚洲欧洲精品一区| 亚洲国产乱码最新视频| 欧美日韩国产精品一卡| 亚洲欧美国产一区二区三区| 正在播放亚洲一区| 国产在线视频欧美| 亚洲国产成人精品久久久国产成人一区 | 欧美大片在线观看| 久久亚洲私人国产精品va媚药| 国产日本欧洲亚洲| 久久免费精品日本久久中文字幕| 久久精品欧洲| 99精品欧美| 一区二区三区在线视频免费观看| 久久久久久伊人| 免费人成精品欧美精品| 中日韩午夜理伦电影免费| 亚洲欧美成人网| 伊人夜夜躁av伊人久久| 亚洲三级免费观看| 国产欧美日韩精品a在线观看| 免费一级欧美在线大片| 欧美伦理在线观看| 久久久久久久久久久一区 | 久久高清国产| 免费观看成人鲁鲁鲁鲁鲁视频| 国产精品99久久久久久人| 欧美一区高清| 一本大道av伊人久久综合| 欧美一区二粉嫩精品国产一线天| 亚洲精品国产拍免费91在线| 亚洲在线1234| 一区二区国产在线观看| 久久都是精品| 西西裸体人体做爰大胆久久久 | 亚洲国产精品999| 国产精品成人一区二区三区吃奶| 免费欧美日韩| 国产亚洲欧美在线| 夜夜精品视频一区二区| 亚洲三级毛片| 久久精品水蜜桃av综合天堂| 香港成人在线视频| 欧美日韩在线一区二区| 91久久久在线| 亚洲电影在线播放| 久久本道综合色狠狠五月| 亚洲尤物在线| 欧美涩涩网站| 亚洲精品一区久久久久久| 亚洲国产婷婷综合在线精品| 欧美一区综合| 久久精彩视频| 国产视频一区欧美| 亚洲制服少妇| 午夜日韩视频| 国产精品乱码| 亚洲午夜视频| 亚欧成人在线| 国产性天天综合网| 欧美一区二区三区免费视| 欧美一区国产在线| 国产欧美日韩视频一区二区三区 | 欧美成人在线免费观看| 精品福利电影| 麻豆成人在线播放| 欧美国产日韩二区| 亚洲精品一二三区| 欧美久久成人| 一卡二卡3卡四卡高清精品视频| 日韩视频在线观看免费| 欧美日韩国产不卡| 亚洲视频免费| 久久国产天堂福利天堂| 国产一区二区三区久久精品| 久久精品在线视频| 欧美成人国产一区二区| 亚洲精品中文字幕在线| 欧美日韩福利视频| 亚洲欧美成人一区二区在线电影 | 久久综合狠狠综合久久综青草| 狠狠色丁香婷婷综合久久片| 久久一日本道色综合久久| 亚洲福利视频网| 亚洲天堂第二页| 国产手机视频精品| 噜噜噜久久亚洲精品国产品小说| 亚洲黄色三级| 午夜亚洲福利| 亚洲国产日韩欧美| 欧美日韩免费网站| 欧美一区在线看| 亚洲国产综合视频在线观看| 亚洲欧美欧美一区二区三区| 黄色成人免费观看| 欧美精品久久久久久久久老牛影院| 亚洲午夜精品视频| 蜜臀久久久99精品久久久久久| 亚洲乱码一区二区| 国产丝袜美腿一区二区三区| 欧美mv日韩mv国产网站| 午夜精品久久久久久久99樱桃| 欧美成人中文字幕在线| 午夜伦欧美伦电影理论片| 在线日韩av| 国产精品一区在线播放| 免费久久99精品国产| 亚洲综合另类| 亚洲精品乱码久久久久久久久| 久久国产精品黑丝| 亚洲精品色婷婷福利天堂| 国产视频精品xxxx| 国产精品福利av| 欧美成年网站| 久久漫画官网| 欧美一区激情视频在线观看| 亚洲美女av在线播放| 欧美成人免费视频| 久久久精品国产免费观看同学| 夜夜嗨av一区二区三区| 亚洲国产91| 国产一区二区精品久久99| 欧美午夜一区| 欧美区国产区| 欧美精彩视频一区二区三区| 久久综合伊人77777麻豆| 欧美一级淫片播放口| 亚洲一区亚洲| 亚洲一区欧美激情| 在线亚洲自拍| 中文av字幕一区| 一区二区日本视频| 日韩小视频在线观看专区| 亚洲福利视频二区| 亚洲第一二三四五区| 欧美刺激午夜性久久久久久久| 看欧美日韩国产| 久久综合影视| 欧美va亚洲va国产综合| 巨胸喷奶水www久久久免费动漫| 久久精品官网| 久久久久九九九九| 久久亚洲午夜电影| 蜜乳av另类精品一区二区| 久久综合伊人| 欧美激情第9页| 亚洲激情在线激情| 日韩一级视频免费观看在线| 亚洲日本中文字幕| 亚洲深夜福利视频| 亚洲欧美视频在线观看| 欧美一级淫片aaaaaaa视频| 久久成人精品无人区| 久久精品一区二区三区中文字幕| 久久九九久精品国产免费直播| 久久尤物视频| 欧美日本韩国在线| 国产精品一区视频| 影音国产精品| 在线亚洲国产精品网站| 亚洲欧美视频在线观看| 久久精品亚洲精品国产欧美kt∨| 久久躁日日躁aaaaxxxx| 亚洲高清不卡| 亚洲男女自偷自拍| 久久午夜影视| 欧美日韩一区二区高清| 国产欧美精品一区二区三区介绍| 国内综合精品午夜久久资源| 亚洲激情在线激情| 亚洲在线免费| 欧美成年人在线观看| 亚洲视频在线观看| 久久九九国产精品怡红院| 欧美精品在线网站| 国产一区二区三区免费不卡| 亚洲人成啪啪网站| 欧美在线免费观看亚洲| 欧美激情国产精品| 亚洲女同精品视频| 欧美成熟视频| 国产视频一区三区| 一区二区三区日韩精品视频| 久久久视频精品| 一本色道久久88精品综合| 久久精品一本| 国产乱子伦一区二区三区国色天香| 亚洲国产精品成人一区二区| 亚洲欧美综合| 亚洲韩国青草视频| 久久久久久久一区二区三区| 国产精品久久久久久久久动漫| 亚洲国产成人精品久久久国产成人一区| 亚洲午夜黄色| 亚洲黄色成人久久久| 久久久久成人精品|