If the constructor of my class inherits a parametrized constructor of another class, will that inherited constructor code be executed before or after the code that I place in my constructor?
For instance in this:
TCurrentKillerTh开发者_运维问答read::TCurrentKillerThread() : TThread(true){
CurrentKillerMutex = CreateMutex(NULL,true,NULL); // protect thread
try {
Write("Created Current Killer");
} __finally {
ReleaseMutex(CurrentKillerMutex);
}
Start();
}
Would TThread(true)
be executed before the code I have in TCurrectKillerThread()
?
Yes. The parent class is always initialized before the derived. You are not inheriting the constructor though - you're calling it.
Yes, C++ construction works from the lowest base class to the most derived one.
Would TThread(true) be executed before the code I have in TCurrectKillerThread()?
Yes, TThread(bool var){ .... }
is executed before TCurrentKillerThread(){ .... }
when the derived class object is instantiated. Construction of parent class sub-object must take place before the derived class sub-object in C++.
Of course, the constructor of base class is executed before the constructor of subclass, and destructor is executed from subclass to base class
精彩评论