/constructors.cpp Secret
Created
August 17, 2023 15:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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