Thread: constructors?

  1. #1
    Registered User
    Join Date
    Feb 2003


    Im having trouble, what exactly is a constructor?

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    a function that get's called on creation of an object. It's what you might have done with InitStruct(&thestruct); in C but it get's called automatically
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    A constructor is nothing compared to a destructor.

    But seriously...a constructor just initializes all your member fields to an initial value. Trust me, you'll come across this situation sooner or later, then you'll say "Ah. That's what its for."

  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    It's a guy in a hardhat that eats from a lunch truck..

    A constructor is a public (normally) function that belongs to a class. When a new object is created, the appropriate constructor (there can be more than one) is automatically called. They are usually used to initialize member variables, call parent class constructors, and really just class initialization in general.

    (I know you didn't ask, but) A deconstructor is similar to a constructor. There may only be one deconstructor in a class. It too is called automatically, but when an object goes out of scope and is used to deinitialize an object (ie: deleting allocated memory, freeing resources, etc).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays and Constructors
    By Verdagon in forum C++ Programming
    Replies: 1
    Last Post: 07-20-2005, 07:20 PM
  2. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  3. constructors, arrays, and new
    By Thantos in forum C++ Programming
    Replies: 6
    Last Post: 05-30-2004, 06:21 PM
  4. constructors in classes
    By Kenman in forum C++ Programming
    Replies: 16
    Last Post: 07-28-2003, 07:35 AM
  5. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 10:16 AM