Thread: Couple Questions

  1. #1
    Unregistered
    Guest

    Couple Questions

    What is a constructor? And what is the 'this' pointer. Thanks guys.

    -CDudd

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    A constructor is called whenever an instance of a class is created on the stack or heap (as long as the memory is allocated with new keyword), to perform initialisation.

    The 'this' pointer points to the current instance of a class from within a class, and is inserted by the compiler as a hidden argument for each class member function call.
    zen

  3. #3
    Unregistered
    Guest
    So the constructor is an initializer for what? The class it is within?
    Thanks

    -CDudd

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    So the constructor is an initializer for what? The class it is within?

    First, you need a class. If you don't know what that is, look it up. You use pre-existing ones or define your own.
    A constructor initializes an object of the class to default values when it's declared. Without one, the object could have incorrect values.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple of Questions About Classes
    By bengreenwood in forum C++ Programming
    Replies: 3
    Last Post: 05-20-2009, 02:50 PM
  2. Couple of questions about XOR linked lists...
    By klawson88 in forum C Programming
    Replies: 5
    Last Post: 04-19-2009, 04:55 PM
  3. Couple of simple directdraw questions.
    By Deo in forum Game Programming
    Replies: 3
    Last Post: 05-25-2005, 07:55 AM
  4. Studying for Final, Couple Questions...
    By stewade in forum C Programming
    Replies: 4
    Last Post: 05-10-2004, 05:02 PM
  5. A couple of Questions
    By johnnabn in forum C++ Programming
    Replies: 4
    Last Post: 02-24-2003, 10:10 PM