Results 1 to 3 of 3

Thread: Object_

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Nov 2007
    Answers
    5

    Object_

    How Object-slicing implemented in c++ ?


  2. #2
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Object_

    For Object slicing refer this link


  3. #3
    Expert Member
    Join Date
    Mar 2012
    Answers
    208

    Re: Object_

    When a Derived Class object is assigned to Base class, the base class' contents in the derived object are copied to the base class leaving behind the derived class specific contents. This is referred as Object Slicing.

    Code:
    class base
    {
         public:
              int i, j;
    };
    class derived : public base
    {
          public:
               int k;
    };
    int main()
    {
          base b;
          derived d;
          b=d;
          return 0;
    }
    here b contains i and j where as d contains i, j& k. On assignment only i and j of the d get copied into i and j of b. k does not get copied. on the effect object d got sliced.

    Last edited by admin; 05-30-2012 at 08:40 AM.

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