|
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <string>
using std::string;
using std::getline;
class Employee
{
private:
string first_name;
string last_name;
int salary;
public:
Employee()
{
setfirst_name();
setlast_name();
setsalary();
}
void setfirst_name()
{
getline(cin, first_name);
}
void getfirst_name()
{
cout << first_name;
}
void setlast_name()
{
getline(cin, last_name);
}
void getlast_name()
{
cout << last_name;
}
void setsalary()
{
cin >> salary;
if (salary < 0)
{
cout << "Error : Initial salary cannot be negative" << endl;
salary = 0;
}
}
void getsalary()
{
cout << salary;
}
};
void main()
{
Employee Employee1, Employee2;
}
이렇게 해봤는데요 출력을하면
Employee()
{
setfirst_name();
setlast_name();
setsalary();
이부분(클래스 생성자) 때문에 바로 입력을 받도록 나오거든요??
근데 클래스 생성자를 쓰지 않으면 제가 생각하는대로 나와요(바로 입력하지 않도록)
클래스 생성자를 쓰면서 바로 입력하지 않도록 하려면 어떻게 고쳐야 하나요??
|