Good afternoon to all.
I am starting with C++ and I have a doubt about using a constructor inside other constructor in a class.
The code like this:
class Empleado{
private:
long dni;
float sueldoBase;
public:
Empleado(){
sueldoBase = 0;
}
Empleado(int dni){
Empleado(); //here I want to replicate the info of the other constructor
this->dni =dni;
}
void mostrarInfo(){
cout<<"DNI : "<<dni<<"\nsueldo base : "<<sueldoBase<<endl;
}
};
int main(){
Empleado John(66561234);
John.mostrarInfo();
return 0;
}
When I get the value of sueldoBase in console it shows me random numbers instead of 0. Note: I know there is a way to use just one constructor but I need to do it with two.
Please help me. Greetings.