Like Tree3Likes
  • 1 Post By grumpy
  • 1 Post By Rodaxoleaux
  • 1 Post By Salem

about constructor

This is a discussion on about constructor within the C++ Programming forums, part of the General Programming Boards category; Hi Guys, If I have a class as: Code: ----------------------------------------------------------------------------- class student { string name; int roll_no; char id; public: ...

  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,202
    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.
    Matticus likes this.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,294
    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
    and the hat of Marriage Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    178
    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?
    Elysia likes this.
    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,&dwBytesWritten);

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,439
    > 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
    manasij7479 likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,168
    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
    4,168
    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
    4,168
    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, 01: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

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