c++ 오류 질문입니다.
늘찬
이 소스를 컴파일 하고 링크 하는데에선 오류가 발생을 안합니다.
그런데 런타임때 오류가 발생하는데 그오류가 메모리 참조 때문에 오류가 걸린건지 모르겠습니다.
무엇때문에 오류가 발생 할까요..???
#includeiostream
using namespace std;
class com{
protected:
char *name;
int pos;
int mtype;
public:
com(char *_name, int _pos, int _mtype);
~com(){
delete []name;
}
char *Getname();
char *Getpos();
char *Getmtype();
virtual int Getsal()=0;
};
com::com(char *_name, int _pos, int _mtype){
name = new char[strlen(_name)+1];
strcpy(name,_name);
pos = _pos;
mtype = _mtype;
}
char *com:: Getname(){
return name;
}
char *com::Getpos(){
char *til[] = {사원,대리,과장,부장,임원};
return til[pos];
}
char *com::Getmtype(){
char *types[]= {시급제,월급제,연봉제};
return types[mtype];
}
class s:public com{
private:
int work;
public:
s(char *_name, int _pos, int _work);
virtual int Getsal();
};
s::s(char *_name, int _pos, int _work): com(name,pos,0){
work = _work;
}
int s::Getsal(){
int sal = work * 10000;
for(int i=0; ipos; i++) sal *= 2;
return sal;
}
class w:public com{
private:
int ser;
public:
w(char *_name, int _pos, int _ser);
virtual int Getsal();
};
w::w(char *_name, int _pos, int _ser): com(name,pos,1){
ser = _ser;
}
int w::Getsal(){
int sal = 2000000;
sal += 200000 * pos;
sal += 50000 * ser;
return sal;
}
class y:public com{
private:
int gra;
public:
y(char *_name, int _pos, int _gra);
virtual int Getsal();
};
y::y(char *_name, int _pos, int _gra): com(name,pos,2){
gra = _gra;
}
int y::Getsal(){
int sal = 20000000;
sal += 10000000 * pos;
sal += 5000000 * gra;
return sal/12;
}
int main()
{
int i;
com *c[] ={
new s(권상우,0,200),
new s(조인성,0,220),
new w(감우성,1,3),
new w(강도원,1,5),
new y(황정민,2,3),
new w(박중훈,2,15),
new w(최민식,3,20),
new y(안성기,4,50)
};
for(i=0; i8; i++){
coutc[i]-Getname()endl;
coutc[i]-Getpos()endl;
coutc[i]-Getmtype()endl;
coutc[i]-Getsal()endl;
delete c[i];
}
return 0;
}