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

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://m.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 閱讀(1070) 評論(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>
            欧美在线看片| 国产日韩成人精品| 亚洲国产精品ⅴa在线观看| 欧美少妇一区| 国产精品久久| 国产欧美一级| 玉米视频成人免费看| 亚洲国产高清自拍| 一区二区电影免费在线观看| 亚洲午夜久久久久久久久电影院 | 亚洲精品在线二区| 99热精品在线| 亚洲欧美日韩国产成人| 欧美综合77777色婷婷| 麻豆av福利av久久av| 亚洲国产精品女人久久久| 亚洲国产精品va在看黑人| 在线综合亚洲欧美在线视频| 亚洲欧美国产日韩天堂区| 久久久久久久高潮| 欧美日韩精品一区二区在线播放| 欧美视频精品在线| 国产一区激情| 一区二区冒白浆视频| 久久久亚洲午夜电影| 亚洲精品一区二区三区99| 午夜精品在线观看| 欧美激情欧美激情在线五月| 国产欧美日韩精品a在线观看| 亚洲第一在线综合网站| 亚洲女人av| 亚洲二区免费| 久久精品国产免费看久久精品| 欧美日韩1区| 亚洲国产成人精品女人久久久| 午夜精品影院| 亚洲美女精品成人在线视频| 久久久人成影片一区二区三区 | 亚洲国产成人精品久久久国产成人一区 | 国产亚洲毛片| 一区二区三区四区五区精品| 久热re这里精品视频在线6| 99精品欧美| 欧美国产激情| 亚洲电影av在线| 久久久久久久久久久久久9999| 99热在这里有精品免费| 久久一二三四| 悠悠资源网亚洲青| 久久久亚洲人| 免费视频久久| 欧美亚洲系列| 国产色综合久久| 欧美一区中文字幕| 亚洲一区二区网站| 国产精品视频内| 亚洲欧美综合精品久久成人| 亚洲精品国产视频| 欧美黄色aa电影| 亚洲精品视频在线观看免费| 欧美激情精品久久久久久久变态| 久久久久99精品国产片| 国产婷婷一区二区| 久久久夜夜夜| 久热这里只精品99re8久| 悠悠资源网亚洲青| 亚洲国产成人精品久久| 欧美日韩1区2区| 亚洲一区二区三区在线观看视频| 亚洲美女视频在线观看| 欧美日韩一区二区在线视频| 中文在线资源观看视频网站免费不卡| 亚洲人成77777在线观看网| 欧美国产成人在线| 亚洲视频久久| 午夜精品在线视频| 樱桃国产成人精品视频| 亚洲国产精品va在线看黑人 | 国产日韩欧美精品| 久久久久久免费| 久久综合色播五月| av成人免费在线| 亚洲一区二区在线播放| 国产午夜精品全部视频播放 | 小处雏高清一区二区三区| 国产在线乱码一区二区三区| 女生裸体视频一区二区三区| 欧美黄色成人网| 欧美一级午夜免费电影| 久久久久一本一区二区青青蜜月| 亚洲日韩视频| 亚洲一区国产一区| 亚洲国产欧美久久| 亚洲一本视频| 亚洲国产裸拍裸体视频在线观看乱了中文 | 美国三级日本三级久久99| 日韩视频一区二区三区在线播放| 9国产精品视频| 精品va天堂亚洲国产| 亚洲精品午夜| 精品91视频| 亚洲天堂av在线免费| 亚洲电影有码| 亚洲欧美日韩在线综合| 欧美福利视频在线观看| 欧美一激情一区二区三区| 六月婷婷一区| 久久激情综合网| 欧美日韩激情小视频| 免费av成人在线| 国产伦精品一区二区三区视频孕妇 | 久久综合给合| 亚洲欧美日韩在线不卡| 蜜乳av另类精品一区二区| 亚洲欧美激情精品一区二区| 蜜月aⅴ免费一区二区三区| 久久久www免费人成黑人精品| 欧美日本韩国| 亚洲国产精品久久久久| 狠狠色狠狠色综合系列| 亚洲一区欧美二区| 亚洲香蕉网站| 欧美日韩国产大片| 91久久精品国产91久久性色tv| 国产亚洲一级| 亚洲欧美三级伦理| 亚洲自拍电影| 欧美性大战久久久久| 亚洲区免费影片| 亚洲精品中文字幕在线| 另类欧美日韩国产在线| 美女福利精品视频| 激情丁香综合| 欧美在线日韩精品| 久久久久国色av免费观看性色| 国产精品午夜国产小视频| 日韩亚洲欧美在线观看| 99re66热这里只有精品3直播| 欧美成人久久| 亚洲黄色小视频| 一本色道久久综合狠狠躁篇的优点| 欧美本精品男人aⅴ天堂| 欧美国产综合一区二区| 亚洲国产精品美女| 免费在线成人| 亚洲黄网站在线观看| 亚洲视频二区| 国产精品国产亚洲精品看不卡15| 一区二区三区免费网站| 亚洲专区一区| 国产日韩视频| 久久免费视频网站| 亚洲第一级黄色片| 亚洲理伦在线| 欧美性猛交一区二区三区精品| 亚洲一区高清| 免费国产一区二区| 日韩视频二区| 国产精品国产一区二区| 久久精品国产精品| 欧美成人免费网站| 一区二区三区鲁丝不卡| 国产精品视频成人| 久久精品首页| 亚洲激情视频网站| 亚洲欧美日韩精品综合在线观看| 久久久久久亚洲精品中文字幕| 久久综合中文字幕| 日韩亚洲欧美一区二区三区| 欧美性天天影院| 欧美中文字幕在线| 亚洲激情黄色| 久久爱www| 亚洲伦理久久| 国产日韩欧美黄色| 欧美激情综合色综合啪啪| 亚洲影视在线播放| 老色鬼久久亚洲一区二区| 欧美日韩另类字幕中文| 午夜视频在线观看一区| 亚洲欧洲美洲综合色网| 久久国产精品网站| av成人福利| 在线播放豆国产99亚洲| 国产精品成人一区二区三区夜夜夜 | 亚洲高清网站| 久久精品国产一区二区三| 日韩视频在线播放| 黄色成人在线观看| 国产精品久久久久久久久久尿| 麻豆精品视频在线| 亚洲欧美综合精品久久成人| 亚洲高清不卡在线| 久久久91精品国产一区二区精品| 一区二区三区免费看| 亚洲国产日韩欧美在线99| 国产目拍亚洲精品99久久精品| 一本色道久久加勒比88综合| 欧美电影电视剧在线观看| 欧美在线www|