Re: [Dev-C++] Derived Classes & Destructors
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <dml...@co...> - 2004-06-21 19:54:36
|
Ahh, that explains my original problem. when I tried to do
//Destructor for B
~B() : ~A()
{
...
}
I got an error, should have thought about it a bit more.
Lior Wehrli wrote:
>Yes, but keep in mind, that while you only have one destructor per class,
>you may have any number of constructors. So while there is no doubt as to
>which destructor will be called (there is only one), it is not clear
>beforehand which constructor will be used. By default, the compiler will use
>the "default constructor" (big surprize!), which is the one having no
>arguments. If you explicitely want to use a different constructor use the
>following syntax:
>
>class B : public A {
> public:
> B(arg1,arg2,arg3) : A(arg1,arg2+arg3) {
> // A::A(arg1,arg2+arg3) will
> // be called BEFORE this
> // constructor executes
>
> // B's specific stuff goes here
> };
>};
>
>greetings
>lior
>
>
>----- Original Message -----
>From: "David McKen" <dml...@co...>
>To: "Mailing List, Dev-Cpp" <dev...@li...>
>Sent: Monday, June 21, 2004 5:24 PM
>Subject: [Dev-C++] Derived Classes & Destructors
>
>
>
>
>>If I have a class B that inherets from a class A and I create an object
>>of type B (call it instance_B).
>>
>>when instance_B is destroyed is the destructor for class A also called?
>>
>>If so does the same thing happen for constructors?
>>
>>
>>
|