#include <iostream>
using namespace std;
class student {
public:
string name;
int age;
bool gender;
//default constructor-->
student(){
cout<<"default constructor"<<endl;
}
//destructor--->
~student(){
cout<<"destructor called"<<endl;
}
//constructor--> parameterised constructor---->
student (string s,int a,bool g){
cout<<" parameterised constructor"<<endl;
name=s;
age=a;
gender=g;
}
//copy constructor-->
student (student &a){
cout<<"copy constructor"<<endl;
name=a.name;
age=a.age;
gender=a.gender;
}
void setName(string s){
name=s;
}
void getname(){
cout<<name<<endl;
cout<<age<<endl;
cout<<gender<<endl;
}
//operator overloading--->
bool operator == (student &a){
if (name==a.name && age==a.age && gender==a.gender) {
return true;
}
else
{
return false;
}
}
};
int main() {
student a("vanshika",19,1);
a.getname();
student b;
student c=a;
c.getname();
if(c==a){ //---->operator overloading
cout<<"same"<<endl;
}
else
{
cout<<"not same"<<endl;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: