Skip to content

Instantly share code, notes, and snippets.

@iraunit
Created August 17, 2023 15:09
#include<bits/stdc++.h>
using namespace std;
class Students{
public:
int rollNo,age;
string name;
int *check = new int;
Students(string s);
//constructor inside class
Students(){
cout<<"Enter Name: \n";
cin>>name;
cout<<"Enter RollNo: \n";
cin>>rollNo;
age = 21;
* check = 123;
cout<<endl;
}
~Students(){
cout<<"Deletd\n";
}
};
// Constructor OutSide Class
Students::Students(string s){
name = s;
rollNo = 5000;
age = 22;
}
int main(){
Students raunit;
cout<<raunit.name<<endl;
Students other("Verma");
cout<<other.name<<endl;
Students raunitCopy(raunit);
// shallow copy example
*raunit.check=321;
cout<<*raunitCopy.check<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment