Thread: about constructors

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    96

    about constructors

    Hi Guys,

    I wanted to know that can we have default constructor and also a parameterized constructor for the same class ?

    eg:

    Code:
    ----------------------------
    class Student
    
    {
    
    private:
    char Name;
    int age;
    
    public:
    
    Student(); //default constructor/
    
    Student(char Name ,int age)  //constructor with parameters/
    
    void getName();
    void getage();
    
    };
    ----------------------------------

    Have I written the parameterized constructor correctly?

    Thanks

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Wow, you have an amazing tendency to repeat same questions again and again!
    About overloaded constructor

  3. #3
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Quote Originally Posted by manasij7479 View Post
    Wow, you have an amazing tendency to repeat same questions again and again!
    And ignore previously given input to boot!

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    I think you haven't read this question carefully, I am asking that can we use "default constructor" and a "parameterized constructor" in the same class?

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by student111 View Post
    I think you haven't read this question carefully, I am asking that can we use "default constructor" and a "parameterized constructor" in the same class?
    I think you haven't read the answers you previously got carefully.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by student111
    I am asking that can we use "default constructor" and a "parameterized constructor" in the same class?
    Yes. It was implied in that other thread by me, then more directly by grumpy.

    I think that you need to learn C++ in a structured way, e.g., by working through a book.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Laserlight,

    Thanks for your reply, well the post was long and I might have missed some points.

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Apparently, he has a problem with my attitude and I'm supposed to care !

    PM:
    Quote Originally Posted by student111
    Well I don't know who you are but you indians have a serious problem with your atittude.
    No where in the post it answers my question clearly.

    My question was simple can I use both "Default Constructor" and "Parameterized Constructor" at the same time in the same class?

    If you can't help then pls don't show attitude.
    Reply:

    And you, regardless of your nationality, are stupid.
    Nobody here is obliged to help you unless you yourself show some effort.

    Quoting grumpy's answer from your last thread:

    Quote Originally Posted by grumpy View Post
    It makes sense to overload a constructor if parameters of differing types can potentially used to create a whole object.

    Let's say int makes sense to construct an object from an integral value in some circumstances, and from a string of characters in other circumstances. Generally, it would then make sense to create two constructors, one that accepts an int, and one that accepts a const char *. I've illustrated this using constructors that only accept one argument, but the principle works if you need to construct objects from multiple items of data (i.e. multiple parameters to the constructor).

    I don't know whether it makes sense in your Vehicle class. In what ways does it make sense to construct a Vehicle?

    I wouldn't supply a default constructor for a class, unless it makes sense to create an object based on nothing (no parameters required).

    Don't read on unless you like technical pedantry. Technically, unless copy constructors (that create an object from an existing object of the same type) are disabled, all constructors are overloaded. The compiler will generate a copy constructor if the programmer doesn't, and it can. It doesn't make sense to have a copy constructor unless there is some other way to create an object to be copied - which means another overloaded constructor must exist. The only exceptions to this are if copy constructors are specifically suppressed.
    Look closely at the bolded regions.
    If that didn't answer your question, nothing but direct spoonfeeding will and you're out of you mind to demand it here.
    Last edited by manasij7479; 06-12-2012 at 12:35 PM.

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Well, you could have written as:

    "Your Question was answered in the previous posts "
    And you could have given the link of that post,alright, before calling me stupid you should see your face in the mirror ok.
    I am more smart then you, I am a human being and can make mistakes but it doesnot mean that you should show your attitude.

    You said:
    I have tendency of repeating the same question".


    Yes , I have faced many indians in my life, you guys are filled in Call Centers and donot provide proper service to anyone.

    Instead of complaining and showing attitude ,do something good in life.

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    I don't want to argue here and I am here to discuss and learn thats it.

    I was not being rude to you but this is not how you reply.

    I can make mistakes as I have said before.
    Last edited by student111; 06-12-2012 at 12:44 PM.

  11. #11
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    You are a champion of programming right, I am new in programming but I don't show attitude ok.

    I am out of practice and have other work to do.

  12. #12
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by student111 View Post
    Well, you could have written as:

    "Your Question was answered in the previous posts "

    I'll write it exactly as I want, not what you want as long as they convey the same message.

    And you could have given the link of that post,alright, before calling me stupid you should see your face in the mirror ok.
    I am more smart then you, I am a human being and can make mistakes but it doesnot mean that you should show your attitude.
    Wow.. philosophical. :P


    *Mods, close this thread if you want*

  13. #13
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by student111 View Post
    Yes , I have faced many indians in my life, you guys are filled in Call Centers and donot provide proper service to anyone.

    Instead of complaining and showing attitude ,do something good in life.
    Now see why I called you stupid ?

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by student111
    well the post was long and I might have missed some points.
    Basically, you didn't understand grumpy's post, hence you should have sought clarification.

    Quote Originally Posted by student111
    Yes , I have faced many indians in my life, you guys are filled in Call Centers and donot provide proper service to anyone.
    Sorry, but this is simply unacceptable. This is an international forum; you do not have a free pass to get away with racism. This is an official warning. Note that if you accumulate three such warnings, you will likely be banned.

    *thread closed*
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constructors
    By MarlonDean in forum C++ Programming
    Replies: 3
    Last Post: 06-18-2008, 01:21 AM
  2. constructors
    By shrivk in forum C++ Programming
    Replies: 7
    Last Post: 06-24-2005, 09:35 PM
  3. constructors?
    By sayword in forum C++ Programming
    Replies: 3
    Last Post: 04-30-2003, 11:56 AM
  4. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 10:16 AM
  5. ()'s in constructors
    By blight2c in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2002, 01:16 AM