Thread: Default Constructors

  1. #1
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002

    Default Constructors

    I have one question regarding default constructors. In java you have a constructor to instantiate objects, but constructors in C++, are used initialize instance variables. If a default constructor doesnt initialize any of the variables, what is the point of one?


    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.


  2. #2
    Registered User
    Join Date
    Aug 2001
    The default constructor generated automatically by the constructor will do the same any other constructor does, namely - make sure the object is in a usable state (that is, initialize anything implementation specific). It will also call the default constructors for base classes and member objects.

    A default constructor written by you can do just about anything.
    - lmov

  3. #3
    Registered User
    Join Date
    Nov 2001
    C++ add a dimension to and already extensible programming language with partial unitialization in the contractors and as function parameters.

    class X
       X(int a = 0, b = 1, char z = TEXT("October"));
       virtual ~X();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Utilizing another compiled program for a task.
    By kotoroshinoto in forum C Programming
    Replies: 6
    Last Post: 06-03-2008, 01:43 PM
  2. Array members copied by the default copy constructors?
    By cyberfish in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2008, 12:46 AM
  3. Default Constructors
    By pritin in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2007, 06:38 AM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  5. Default Constructors w/Classes as Parameters
    By GrNxxDaY in forum C++ Programming
    Replies: 22
    Last Post: 07-31-2002, 07:50 AM