내 하위 클래스에있는 일부 문자열을 표시하는 데 문제가 있습니다. 함수를 사용하여이 작업을 수행하려고 시도하지만 이러한 문자열의 내용을 왜 얻지 못하는지 확신 할 수 없습니다.C++ 예외 처리 내 자신의 예외 클래스
class Employee{
string FN, LN, JT;
double Income;
public:
char const *getters(){
return FN.data(), LN.data(), JT.data(); //=========>getting the content of strings
}
virtual char const *getAccess()=0;
Employee(char const *fn, char const *ln, char const *jt, double inc){
if(fn==0) throw Exception(1, "Sorry, First Name is Null");
if(ln==0) throw Exception(2, "Sorry, Last Name is Null");
if(jt==0) throw Exception(3, "Sorry Job Title is Null");
if(inc<=0) throw Exception(4, "Sorry, The Income is Null");
FN=fn;
LN=ln;
JT=jt;
Income=inc;
}
};
class Programmer: public Employee{
public:
Programmer(char const *fn, char const *ln, double inc):
Employee(fn,ln,"Programmer", inc)
{}
char const *getAccess(){
return "You have access to Meeting Room + Development Office";
}
};
//=========The Main============
int main(){
Employee *acc[3];
try{
acc[0]=new Programmer("Juan", "Villalobos", 60000);
acc[1]=new Director("Jorge", "Villabuena", 70000);
acc[2]=new ProdSupport("Pedro", "Villasmil", 80000);
for(int i=0; i<3; i++){
cout << acc[i]->getters() << endl; //=============>Displaying the strings
cout << acc[i]->getAccess() << endl;
}
} catch(Exception acc){
cout << "Err:" << acc.getErrCode() << " Mess:" << acc.getErrMess() << endl;
}
return 0;
}
그래서 내 기능이 내가 원하는 것을 수행하지 않는다고 생각합니다. 이름과 성을 표시합니다. 내가 뭘 잘못하고 있니?
이 그렇게 잘못 내가 아니다 :
이하지만 당신은 아마 원하는 것은
이 같은 프로그램을 다시 작성합니다입니다
컴파일 않습니다 어디서부터 시작해야할지 ... –
이 경우에는 직책이 JT.d와 동일한 마지막 문자열 만 가져 오는 것을 잊어 버렸습니다. ata() – JV17
당신이하려고하는 것처럼 문자열 목록을 반환 할 수있는 아이디어가 있습니까? 함수에서 리턴 값은 하나뿐입니다. –