Planet of NCCUCS
adobe photoshop 8.0 warez Adobe Premiere Pro CS5 can t reinstall adobe creative suite download adobe photoshop 8 0 cs Adobe Illustrator CS5 adobe premiere pro 1.5 serial key adobe acrobat reader 6.0 free Adobe Dreamweaver CS5 adobe course indesign software adobe photoshop free cursive fonts Adobe Photoshop CS5 Extended adobe photoshop elements 4 help sound adobe photoshop logos Adobe Creative Suite 5 Master Collection adobe creative suite torrents adobe photoshop and trial version Adobe Acrobat 9 Pro Extended adobe photoshop shape tools adobe photoshop free trial software Adobe Contribute CS5 wartz adobe acrobat adobe creative suite 2 academic Adobe Indesign CS5 adobe acrobat approval adobe premiere preview download Adobe Flash Catalyst CS5 602 acrobat adobe reader update adobe acrobat 7 reader update Adobe Flex Builder 3 Pro opening pps in adobe photoshop

default constructor

作者:lui on 十月 1, 2008 Posted in RSS | | 觀看文章來源

C++中預設建構子就是沒有參數的建構子



一般大多數人都有以下錯誤觀念:

1.class沒有定義預設建構子 compiler就會自動產生一個

2.compiler產生出來的預設建構子中 會為member data設預設值



在C++ standard(ISO/IEC 14882)中說明:

“The implementation will implicitly declare these member functions for a class type when the program does not explicitly declare them, except as noted in 12.1. The implementation will implicitly define them if they are used”



當compiler有需要而又沒有時才會產生出來 所以沒需要時就不會產生



那甚麼時候需要呢! 文件中說明:

“If there is no user-declared constructor for class X, a default constructor is implicitly declared. An implicitly-declared default constructor is an inline public member of its class. A constructor is trivial if it is an implicitly-declared default constructor and if:
— its class has no virtual functions (10.3) and no virtual base classes (10.1), and
— all the direct base classes of its class have trivial constructors, and
— for all the nonstatic data members of its class that are of class type (or array thereof), each such class has a trivial constructor.
Otherwise, the constructor is non-trivial.”



所以說需要的定義取決於 1.virtual functions, 2.virtual inherited, 3.base class and 4.data members.



1.virtual functions

當一個類別定義virtual functions後,每一個物件都必須有一個virtual function table記錄virtual function的位址,因此compiler會自動擴張物件的data member,產生這個table並且加入一個指標指向這個table。



2.virtual inherited

(待補)



3.base class

當一個class沒有任何預設建構子而它的base class有預設建構子時,那麼必須需呼叫base class的預設建構子,所以compiler自動擴張一個預設建構子,其中呼叫bass class的建構子。



如果存在建構子的話,compiler會擴張建構子做上述事情而不擴張一個預設建構子。文件的解析是由於使用者定義的建構子存在下就不會隱含產生預設建構子。



4.data members

同理。當data member中,存在至少一個物件有預設建構子時。

:

讀過本文的讀者, 也對以下文章有興趣

No comments for this entry yet...

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

最新文章

照片

R0012028R0012036R0013553R0013551R0013550R0013549R0013560R0013558R0013569R0013561R0013570R0013571R0013580R0013581R0013556R0013567R0013563R0013572R0011783R0012312