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

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 閱讀(1062) 評論(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歲后不失業(yè), 不能心浮, 要靜心好好地去學!

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

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

<2006年9月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

常用鏈接

留言簿(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>
            久久免费偷拍视频| 久久综合狠狠综合久久综合88| 在线午夜精品自拍| 老司机成人在线视频| 国产日韩亚洲欧美综合| 在线视频你懂得一区| 亚洲国产高清高潮精品美女| 午夜视频久久久| 国产欧美日韩视频一区二区三区| 亚洲午夜在线观看视频在线| 亚洲日本va在线观看| 欧美激情免费在线| 99亚洲一区二区| 亚洲乱码精品一二三四区日韩在线| 免费观看30秒视频久久| 亚洲国产精品一区二区第四页av| 狂野欧美激情性xxxx欧美| 久久久久久自在自线| 亚洲国产高清一区| 亚洲国产日韩美| 欧美视频你懂的| 午夜视频一区二区| 欧美一区二区免费观在线| 久久精品亚洲| 久久久精品动漫| 亚洲国产精品久久人人爱蜜臀| 欧美黄色免费网站| 欧美午夜片在线观看| 性视频1819p久久| 久久精品国产v日韩v亚洲 | 亚洲视频精选在线| 国产美女精品免费电影| 久久精品中文| 欧美激情综合在线| 欧美一区二区三区视频| 久久久www| 日韩一级大片| 亚洲欧美日韩一区二区三区在线观看 | 亚洲免费大片| 亚洲午夜极品| 加勒比av一区二区| 亚洲人成网站精品片在线观看| 国产精品xxxxx| 久久频这里精品99香蕉| 欧美精品综合| 久久久久成人精品免费播放动漫| 农村妇女精品| 久久精品国产第一区二区三区| 欧美国产精品v| 久久久久青草大香线综合精品| 欧美激情第10页| 久久精品一区二区三区不卡| 欧美视频在线观看| 欧美激情1区2区| 国产色综合久久| 99日韩精品| 亚洲黄色成人久久久| 午夜久久99| 亚洲一区免费视频| 免费在线成人| 久久青草久久| 国产麻豆日韩| 99re视频这里只有精品| 91久久国产综合久久91精品网站| 性色av香蕉一区二区| 一区二区三区四区五区视频| 能在线观看的日韩av| 久久亚洲欧美| 国产三级欧美三级| 亚洲视频导航| 正在播放亚洲一区| 欧美精品在线免费播放| 欧美激情综合| 亚洲韩国精品一区| 毛片精品免费在线观看| 久久欧美肥婆一二区| 国产欧美精品久久| 亚洲午夜久久久久久久久电影院| 国产精品久久国产精品99gif| 免费亚洲电影| 一区二区亚洲精品国产| 亚洲自拍偷拍麻豆| 亚洲一区成人| 欧美视频免费看| 亚洲毛片在线观看| 99国产精品久久久久久久成人热 | 欧美日本一道本在线视频| 欧美大片一区二区| 亚洲黄色一区| 欧美黄色aa电影| 最近看过的日韩成人| 亚洲精品你懂的| 欧美激情在线免费观看| 亚洲精品日产精品乱码不卡| 一本久久a久久免费精品不卡| 欧美精品日韩| 99在线视频精品| 欧美专区在线观看一区| 黄色在线成人| 欧美黄色精品| 在线一区二区三区四区五区| 欧美一区二区在线看| 韩国av一区二区三区| 久久一二三国产| 亚洲狠狠婷婷| 亚洲免费在线视频| 国产欧美一区视频| 久久久久国产精品麻豆ai换脸| 欧美成人精品h版在线观看| 91久久国产综合久久| 欧美精彩视频一区二区三区| 亚洲视频一区二区| 久久这里有精品视频| 一区二区高清视频在线观看| 国产精品永久在线| 久久久亚洲欧洲日产国码αv| 欧美韩国日本综合| 亚洲综合色网站| 国产一区日韩二区欧美三区| 欧美不卡高清| 亚洲一区二区三区免费观看| 欧美影院成年免费版| 亚洲国产乱码最新视频| 欧美日韩一二区| 久久九九99视频| 99re热这里只有精品免费视频| 久久激情五月激情| 日韩视频欧美视频| 国产日韩欧美中文在线播放| 欧美ed2k| 久久国产精品久久精品国产| 亚洲国产欧美日韩精品| 欧美一区二区三区精品电影| 亚洲大片精品永久免费| 欧美日韩在线电影| 久久一区二区三区超碰国产精品| 亚洲图片激情小说| 亚洲国产成人精品久久| 久久久久久久激情视频| 亚洲午夜在线| 亚洲精品综合精品自拍| 国语自产精品视频在线看抢先版结局 | 欧美在线亚洲| 亚洲精品一区二区三区不| 国产欧美日韩一区二区三区在线 | 亚洲一区二区黄色| 在线欧美影院| 国产精品一区二区三区久久久| 欧美ab在线视频| 香蕉乱码成人久久天堂爱免费 | 亚洲欧美日韩中文视频| 亚洲人成啪啪网站| 在线精品福利| 国产在线精品成人一区二区三区| 欧美人在线视频| 免费在线成人| 久久精品免费| 欧美怡红院视频| 亚洲欧美一级二级三级| 99re视频这里只有精品| 亚洲国产日韩在线| 欧美成人国产va精品日本一级| 久久久久九九视频| 翔田千里一区二区| 亚洲欧美日韩视频二区| 亚洲视频在线观看网站| 日韩天天综合| 9久re热视频在线精品| 亚洲免费福利视频| 日韩午夜一区| 99精品久久久| 亚洲伦伦在线| 91久久精品国产91性色| 亚洲欧洲精品一区二区三区不卡| ●精品国产综合乱码久久久久 | 99在线精品视频| 亚洲精品1区| 亚洲精选久久| 中文一区二区在线观看| 中国成人在线视频| 亚洲一级二级| 午夜精品在线| 久久久久国产精品人| 久久久久女教师免费一区| 久久在线免费| 欧美高清在线视频观看不卡| 欧美日韩国产123区| 欧美日韩亚洲综合| 国产精品色网| 狠狠色丁香婷婷综合| 亚洲国产成人一区| 99热免费精品在线观看| 亚洲综合视频一区| 欧美在线网址| 欧美成人福利视频| 一区二区成人精品 | 国模叶桐国产精品一区| 在线观看日韩| 日韩视频中文字幕| 欧美一区二区三区四区高清|