Java has super (), but not in C + +. Take a look at this piece of code:
classA { Public: A () {printf ("A () \ n"); } A (intd) {printf ("A (int) \ n"); A (); } //Cannot call constructor like this! Another anonymous object is generated ~a () {printf ("~a \ n"); } voidDDD () {printf ("ddd \ n"); } };intMainintargcChar*argv[]) {A aaa (9); AAA.DDD (); GetChar (); return 0;}
The output is:
A (int)
A ()
~a
Ddd
But if you change it into
A (int d) {printf ("a (int) \ n");}
The output is:
A (int)
Ddd
Fully prove that there is an anonymous object generated and destroyed in the middle! And I don't know if there's an official solution at the moment, but if you want to define the init () function, forget it.
Reference:
Http://www.cnblogs.com/xkfz007/archive/2012/05/11/2496447.html
Some discussions:
http://bbs.csdn.net/topics/80415554
---------------------------------------------------------------------
However, you can explicitly call destructors, as a reference:
http://fpcfjf.blog.163.com/blog/static/55469793201362442256498/
C + + cannot explicitly call constructors, and it generates anonymous objects, which is completely different from Java!