c++ 오류 질문입니다.
발랄한그1녀
이 소스를 컴파일 하고 링크 하는데에선 오류가 발생을 안합니다.
그런데 런타임때 오류가 발생하는데 그오류가 메모리 참조 때문에 오류가 걸린건지 모르겠습니다.
무엇때문에 오류가 발생 할까요..???
#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;
}
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752085 | 문자열을 랜덤하게 출력해서 대체,삽입,삭제 횟수를 각가 표시하고 그걸 표 형태로 출력 | 슬아s | 2026-10-20 |
| 2752056 | 포인터 && 배열 질문요~ (2) | 해찬나래 | 2026-10-20 |
| 2752031 | x^n 구하는 코드 짜봤는데 값이 틀려요 ㅠㅠ | 세실 | 2026-10-20 |
| 2752000 | 나 정말 미치겠어요..ㅠㅜ (4) | 다이 | 2026-10-20 |
| 2751978 | 문자열 질문이요.. | 초시계 | 2026-10-19 |
| 2751945 | 숫자 맞추는 프로그램이요 ㅠㅠ (1) | 동은 | 2026-10-19 |
| 2751917 | C언어 이중 연결 관련 질문합니다. | 유우 | 2026-10-19 |
| 2751888 | return의 정확한 의미좀 알려주세요 (3) | 올해1살 | 2026-10-19 |
| 2751857 | 포인터 배열 (2) | 터큰 | 2026-10-18 |
| 2751831 | 연산자? 질문입니다 (2) | 진주 | 2026-10-18 |
| 2751800 | C언어 기초질문입니다.. (3) | 핫블랙 | 2026-10-18 |
| 2751739 | 파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요. (2) | 얼 | 2026-10-17 |
| 2751715 | unresolved external symbol 에러... | 이룩 | 2026-10-17 |
| 2751686 | 변수 설정에 관한 질문입니다. | 꽃달 | 2026-10-17 |
| 2751655 | 자료구조 연습문제 | 한무릎 | 2026-10-17 |
| 2751631 | gets 함수 질문이요. (4) | 해늘 | 2026-10-16 |
| 2751553 | 퀵정렬 소스인데 주석좀 달아주세요 (1) | 싴흐한세여니 | 2026-10-16 |
| 2751528 | 저기 이거하는법좀 질문.. (2) | 가람슬기 | 2026-10-15 |
| 2751445 | 도저히 풀 수가 없네요.... (2) | 신당 | 2026-10-15 |
| 2751412 | 어제부터 계속 해도.........안되는.... (1) | 족장 | 2026-10-14 |
