A short question about Destructors

Hello,
I'm new here and new to C++....and I have a short question.
Does a Class always need a "Destructor" ?? (For example a class like
1
2
3
4
5
6
7
8
9
10
class zwei{
   double a;
   double b;
public:
//Constructor
   zwei();
   zwei(double, double);   
   double geta(){return a;}
   double getb(){return b;} //better now ?
}
)

I thought there always has to exist a Destructor to any class......or does it depend on the class itself or maybe its usage ?? A short answer (like "yes, it has to exist" or "No, it depends...." would be enough for me at the moment.
Last edited on
In C++, a class will always have a destructor. If you don't write one, you get one for free provided for you.

In your class above, a destructor is made for you because you didn't write one yourself.
Oh, that's very nice. I didn't expect such service....

Thanks for the quick answer. That helps me indeed. But i'm afraid it won't take long until the next question arises.
Is your next question going to be about the missing semicolon after the closing brace of the class?

Also, try not to get into the habit of providing get functions for every member variable.
Indeed, given that the variables being fetched are public anyway, the get functions are completely superfluous.
Hang on, a & b are private by default, aren't they?

Now that I have asked this question, I should point out to everyone that Moschops has vastly more knowledge & experience than me (though you all probably knew that anyway)
Oops, sorry. I could have sworn that when I looked at that they were public... maybe I misread, or maybe the code changed since I first read it :p Anyway, yes, looking at it now, they're definitely private. Ignore me.
Last edited on
Ignore me.


Never going to do that - always look forward to what you have to say. Meanwhile, I have lost count of MyClangers total !!!!

Edit:
The OP did edit the post 15 minutes after.
Last edited on
Gah, I hate it when somebody beats me to answering the question. Q.Q
Topic archived. No new replies allowed.