Results 1 to 7 of 7

Thread: About Argument in C++

  1. #1
    Contributing Member
    Join Date
    Jul 2006
    Answers
    50

    About Argument in C++

    Can a default constructor in C++ have one argument? If so can someone give example for this?


  2. #2
    Junior Member
    Join Date
    Sep 2006
    Answers
    27

    Re: About Argument in C++

    In fact a default constructor has no arguments in it and so in other words is also called as no argument constructor.So I think it is not possible for a default constructor to have one argument.


  3. #3
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    Re: About Argument in C++

    If a constructor has an argument it will no more be called a default constructor becaue default constructor is a special case of constructor which doesn't take any arguments. It is defined that way.

    You can always pass an argument to the constructor. But, as soon as you do that, it is no more a default constructor!


  4. #4
    Contributing Member
    Join Date
    May 2006
    Answers
    85

    Re: About Argument in C++

    Friends I think a constructor can have default arguments.Only if a constructor has any arguments that do not have default values, it is not a default constructor. This is just my idea. Post your thoughts on this.


  5. #5
    Expert Member
    Join Date
    Sep 2006
    Answers
    477

    Re: About Argument in C++

    Norman, if you had read all the replies for this thread you'd have realized whatever you have told has already been told by everyone.

    We all know constructor can have arguments. The question was can Default constructor have arguments. Well, the answer everyone gave makes sense. (If the constructor has an argument, it won't be called default constructor)

    [COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

    Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"

  6. #6
    Expert Member
    Join Date
    Oct 2005
    Answers
    383

    Re: About Argument in C++

    hi
    no default constructor cannot have one argument.

    Remember when you donot explicitly define a constructor for a class,then java creates a Default constructor for the class.The default constructor automatically initializes all instance variables to "zero". Once u define ur own constructor ,the Default constr is no longer used.

    A constructor with one parameter is called "paramerized constructor".
    Hop thsi ans satisfies u.
    bye


    :)
    NEVER SAY DIE.

  7. #7

    Re: About Argument in C++

    No, Never. A default constructor can not have arguments..


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact