Thread: about constructor

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

    about constructor

    Hi Guys,

    If I have a class as:

    Code:
    -----------------------------------------------------------------------------
    class student
    
    {
    
    string name;
    int roll_no;
    char id;
    
    public:
    
    student(int,char,string); ---->constructor with parameters
    
    };
    ------------------------------------------------------------------
    I wanted to know that can we initialize the data members of the class student just by using the data types in constructor?
    Last edited by student111; 06-27-2012 at 06:27 AM. Reason: correcting

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Have you tried reading a basic textbook?

    This is just one more example of a question that you would be able to answer yourself, if you bothered to read a basic textbook or tutorial.

    Sorry but your approach of asking such things, and hoping others will explain, is a tactic that my six-year-old nephew uses. And even he knows there is a limit on how often he can use such a tactic without annoying his friends or family.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by student111
    Have you tried reading a basic textbook?

    This is just one more example of a question that you would be able to answer yourself, if you bothered to read a basic textbook or tutorial.
    Apparently, student111 lost the textbook he/she was using, but somehow refuses to take the suggestion of getting a replacement if it really cannot be found.
    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

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  5. #5
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    Why do you keep posting the same question and when someone answers it, you ignore it and make a new thread asking the same question?
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Why do you keep posting the same question and when someone answers it, you ignore it and make a new thread asking the same question?
    And these are just the ones on ctor and dtor
    constructor and its uses
    about destructor
    about constructor and class
    About overloaded constructor
    about constructors
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I've been asking that for a couple of weeks now.

    Unsurprisingly I've gotten no answer.

    Soma

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Well I think their was no use of firing all this as you must have read what Laserlight has said.
    I have seen different ways of initializing objects using constructor in different resources, so I was a bit confused of how can we initialize data members using constructors.

  9. #9
    Registered User
    Join Date
    Nov 2011
    Posts
    96
    Hi,

    I was a bit confused over different ways of initialization that was done using constructor,so I posted the question here.
    I agree,similar questions do become annoying, I have got those links and I'll look into them.

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I have got those links and I'll look into them.
    You mean the links that people already posted for you in earlier threads?

    You are going to "look into them" this time around?

    Wow. So, you've actually just admitted to not paying any attention to the people trying to help you. Awesome.

    Soma

  11. #11
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Can we ban people for being a nag?
    Obviously not or I would have been banned for harping on about style and variable naming by now.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-23-2012, 10:47 PM
  2. Replies: 5
    Last Post: 02-21-2011, 02:19 AM
  3. Specialized Constructor call Default Constructor
    By threahdead in forum C++ Programming
    Replies: 15
    Last Post: 08-23-2010, 03:39 PM
  4. Replies: 6
    Last Post: 05-19-2010, 04:03 AM
  5. Replies: 10
    Last Post: 06-02-2008, 08:09 AM