Results 1 to 8 of 8

Thread: Copy Constructor

  1. #1
    Junior Member
    Join Date
    Dec 2007
    Answers
    2

    Copy Constructor

    While we create a copy constructor Is this code coreect or wrong?
    class a
    {
    public:
    a(a &b)
    {}
    }


  2. #2
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    Re: Copy Constructor

    It should be like ::

    class a
    {
    public:
    a(const a &b)
    {}
    }


  3. #3
    Junior Member
    Join Date
    Dec 2007
    Answers
    1

    Post Re: Copy Constructor

    Quote Originally Posted by manoj200724 View Post
    While we create a copy constructor Is this code coreect or wrong?
    class a
    {
    public:
    a(a &b)
    {}
    }

    This is absolutely correct. const is required to prevent the passing object being changed by copy constructor code.

    Last edited by vikram_lok; 12-12-2007 at 02:50 AM.

  4. #4
    Contributing Member
    Join Date
    Nov 2007
    Answers
    46

    Re: Copy Constructor

    i think its working. i will say tomorrow how it works


  5. #5
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: Copy Constructor

    Copy constructor can be like this

    B(const B &b)
    {
    //initialization
    }


  6. #6
    Junior Member
    Join Date
    May 2008
    Answers
    4

    Re: Copy Constructor

    ur code is absolutely correct


  7. #7
    Junior Member
    Join Date
    May 2008
    Answers
    4

    Re: Copy Constructor

    that code is correct,but if u create a constant object then dt code is not correct,u have to write const classname&,like dt.ok,,,,,,,if u do not write const object then dt code is ok.


  8. #8
    Junior Member
    Join Date
    Jun 2008
    Answers
    2

    Re: Copy Constructor

    What ever u have written that is absolutely correct...


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