K
kasiyil
Hello,
I have a question about constructors and destructors in C++. Assume
that I declared a class that has a constructor and virtual destructor
like below:
class X {
X() { printf ("Hi\n"); }
virtual ~X() { }
}
When I derive a class from X called Y, and do not define any
constructor or destructor;
class Y : public X {
void hi() { printf ("Hiiiiiii\n"); }
}
what is the behaivour of the compiler? Does the compiler generates a
constructor that automatically calls X's constuctor? Does the compiler
generates a virtual destructor automatically? Do I need to implement a
virtual destructor?
I have a question about constructors and destructors in C++. Assume
that I declared a class that has a constructor and virtual destructor
like below:
class X {
X() { printf ("Hi\n"); }
virtual ~X() { }
}
When I derive a class from X called Y, and do not define any
constructor or destructor;
class Y : public X {
void hi() { printf ("Hiiiiiii\n"); }
}
what is the behaivour of the compiler? Does the compiler generates a
constructor that automatically calls X's constuctor? Does the compiler
generates a virtual destructor automatically? Do I need to implement a
virtual destructor?