2dix-The Student Choice
Log in Register now

Program for concept of object slicing in c++

Develop a program for concept for object slicing in c++  ?

object slicing:
                           It the concept by virtue of which we can assign same parameters from derived class to its base class.
example:

#include<iostream>
#include<conio.h>
using namespace std;
class base 
{
protected:
int a,b,c;
public:
base()
{
a=b=c=0;
}
void display()
{
cout<<a<<endl<<b<<endl<<c<<endl;
}
};
class derived:public base
{
int k,l;
public:
derived()
{
a=5;b=6;c=10;k=4;l=5;}
};
main()
{
derived d;
base b;
b.display();
b=d;
b.display();
        getch();
}

output:
0
0
0
5
6
10


comments (1)

avatar