开发者

symbian C++ constructor

how 开发者_如何学Cthe private constructor works in Symbian C++??


If I recall correctly, Symbian C++ did not have support for correct exception handling, and based object creation on a two step initialization process --the constructor cannot throw, so there is a simple no throw constructor and then an initialization step. One of the problems with two phase initialization is that it places the burden of performing the construction and initialization (two separate steps) in user code, and that is error prone as you have to remember in each object creation.

To ease that burden, the design depended on static functions like NewL, NewLC (I don't remember if there were more of these). In that environment, having the constructor private inhibits user code from creating objects of the type without following the two-phase initialization, and forces them to use the provided NewXXX mechanism. These functions, being part of the class have access to the private constructor, and instantiate the object and then perform any initialization.


I'm not aware of any reasons for private constructors that are specific to Symbian C++, but there are uses in any C++ code, depending on functionality being presented and the controls against accidental misuse. You may be interested in the discussion at http://discussion.forum.nokia.com/forum/showthread.php?215249-Constructor-in-symbian-c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜