Constructor | Deconstructor

Hi people,

I am doing the tutorial from this website, and I did the part of classes, but there is one thing that I don't understand: what is the use of constructors and deconstructors? Could anyone explain that?
Thanks in advance!
Constructors and destructors will implicitly run when and object is created or deleted respectively.

You'd normally use constructors for initialising class values.

You'd normally use destructors for tidying up. Maybe deleting assigned memory and such.
So you use the constructor to assign values to private/protected variables?
You can use constructors to set the state of your object. Depending on the situation in your program, you may need one of a dozen different states. So you can overload constructors to allow this to happen.

tl;dr
Constructors are used to initialize members, while destructors are used typically to free up dynamically allocated memory.
Thanks! I'm starting to get it :) but could you give an example of a state?
Topic archived. No new replies allowed.