I have created a class name Employee
and inside that I have declared a function and two variable(name ,age) . After creating a variable x
I am not getting the name insted getting empty name
and age =0
CODE:
#include<iostream>
using namespace std;
class Employee{
public:
string name;
int age;
void print(){
cout<<"Name:"<<name<<endl;
cout<<"Age:"<<age<<endl;
}
Employee(string name,int age){
name = name;
age=age;
}
};
int main(){
Employee x=Employee("chang",33);
x.print();
return 0;
}
Expected:
name:Chang
age :33
OutPut:
name:
age :0
Can Someone tell me what is the reason behind it.