Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Conversion from Class Type to Class Type
- using constructor
- */
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class D{
- int m;
- public:
- D(int);
- ~D();
- void show();
- int getM();
- };
- class C{
- int m;
- public:
- C(D&);
- C(int);
- ~C();
- void show();
- };
- inline int D::getM(){
- return m;
- }
- inline C::C(D &obj){
- m = obj.getM();
- }
- inline C::C(int m){
- C::m = m;
- }
- inline C::~C(){
- cout << "Destructor Called for C" << endl;
- }
- inline D::D(int m){
- D::m = m;
- }
- inline D::~D(){
- cout << "Destructor Called for D" << endl;
- }
- inline void D::show(){
- cout << m << endl;
- }
- inline void C::show(){
- cout << m << endl;
- }
- int main() {
- D obj1(3);
- cout << "obj1.m = ";
- obj1.show();
- C obj2 = obj1;
- cout << "obj2.m = ";
- obj2.show();
- cin.get();
- return 0;
- }
Add Comment
Please, Sign In to add comment