Default Constructors

This is a discussion on Default Constructors within the C++ Programming forums, part of the General Programming Boards category; I have one question regarding default constructors. In java you have a constructor to instantiate objects, but constructors in C++, ...

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

    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?

    Thanks
    -MethodMan-

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

    Homepage: http://www.freewebs.com/andy_moog/home.html

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    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
    Posts
    1,348
    C++ add a dimension to and already extensible programming language with partial unitialization in the contractors and as function parameters.

    Code:
    class X
    {
       X();
       X(int a = 0, b = 1, char z = TEXT("October"));
       virtual ~X();
    }
    Kuphryn

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, 02: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, 07:38 AM
  4. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 05:24 PM
  5. Default Constructors w/Classes as Parameters
    By GrNxxDaY in forum C++ Programming
    Replies: 22
    Last Post: 07-31-2002, 08:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21