• Advertisement
Sign in to follow this  
  • entries
    114
  • comments
    126
  • views
    64520

Project

Sign in to follow this  

124 views

Well, I got most of the project done. I am sort of confused with constructor / destructors though. I should work with it more until I understand the concept more, but I did go ahead and finish chapter 7.

Anyway, I love working on these programs, really gets the mind working :)
Sign in to follow this  


2 Comments


Recommended Comments

The constructor is called when you create an object. If you don't specify a constructor, the compiler defines one itself. You can overload constructors too. If you have some kind of string class, you could have a contructor that takes no arguments (just creates an empty string). Then you could also have a constructor that takes one argument, a string (the "abcdefg" kind of string in this case, not std::string), and initializes your string with that literal. The first constructor I mentioned would be created with "myString someString;", but the second one would be with "myString someString("Test");". That's basically a constructor for you.

Destructors are the same way, except you can't overload them, and they don't take parameters. If you try to have an argument with a destructor, they'll explode. [lol] [grin]

Share this comment


Link to comment
In a nutshell, constructors are where you create objects and destructors are when you destroy objects (such as where you delete the memory you've allocated, etc).

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement