Subscribe Us

Responsive Advertisement

Advertisement

Copy Constructor in C++ | OOP

 

Copy Constructor in C++ | OOP




#include<bits/stdc++.h>

using namespace std;

class student

{

    string name;

    int roll;

public:

      student(){}

      student(string s,int x)

      {

          name=s;

          roll=x;


      }

      student(student &s1);

      void show()

      {

          cout<<name<<endl<<roll<<endl;

      }

};

student ::student(student &s1)

{

    roll=s1.roll;

    name=s1.name;

}

int main()

{

    student s("Ujjal",1);

    s.show();

   student s2;

   s2=s;

   s2.show();

    return 0;

}


Post a Comment

0 Comments