Program related to Object Slicing : Why the output is not coming In Base a=2 ?
2 posters
Page 1 of 1
Program related to Object Slicing : Why the output is not coming In Base a=2 ?
- Code:
//Object Slicing
#include<iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base(int x)
{
a=x;
}
void show()
{
cout<<"\nIn Base :a="<<a;
}
};
class Derived : public Base
{
private:
int b;
public:
Derived(int x,int y):Base(x)
{
b=y;
}
void show()
{
cout<<"\nIn Derived :a="<<a<<" and b="<<b;
}
};
int main()
{
Base B(5);
Derived D(2,3);
B.show();
return 0;
}
iamdsc_0410- Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani
Re: Program related to Object Slicing : Why the output is not coming In Base a=2 ?
- Code:
//Object Slicing
#include<iostream>
using namespace std;
class Base
{
protected:
int a;
public:
Base(int x)
{
a=x;
}
void show()
{
cout<<"\nIn Base :a="<<a;
}
};
class Derived : public Base
{
private:
int b;
public:
Derived(int x,int y):Base(x)
{
b=y;
}
void show()
{
cout<<"\nIn Derived :a="<<a<<" and b="<<b;
}
};
int main()
{
Base B(5);
B.show();
Derived D(2,3);
D.show();
B=D;
B.show();
return 0;
}
akarshsomani- Posts : 21
Join date : 2017-04-04
Similar topics
» templet program
» please check the error and correct the program
» Overloading new and delete operator program
» IP6: Write a C++ program that uses the concept of hybrid inheritance.
» Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!
» please check the error and correct the program
» Overloading new and delete operator program
» IP6: Write a C++ program that uses the concept of hybrid inheritance.
» Program given by sir i.e given in Reema Thareja on Overloading of new and delete operators is not working . Debug it !!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|