상속된 객체의 _vptr?
글쓴이: purewell / 작성시간: 금, 2003/07/04 - 11:25오전
class CParent { protected: int k[200]; public: virtual void SomeProcess(void)=0; CParent(); virtual ~CParent(); }; class CChild : public CParent { public: void SomeProcess(void) {...} CChild(); virtual ~CChild(); };
CParent* pPerson; pPerson=new CChild[1000]; if (!pPerson) {printf("줸장"); exit(0);} for (int i=0; i<1000; i++) { pPerson[i].SomeProcess(); }
이때 위의 코드에서 i=1일 때 SIGSEGV를 받습니다.
gdb로 돌려보면
Quote:
pPerson[0] = {_vptr.CParent = 0x8053bb8, ... }
pPerson[1] = {_vptr.CParent = 0xffffffff, ... }
pPerson[2] = {_vptr.CParent = 0x00000000, ...}
ㅡ_-) 분명 new로 배열로 선언해줬고
pPerson가 가르키는 주소 역시 NULL이 아님을 확인했는데...
무엇이 문제일까요...
Forums:
[code:1]CParent* pPerson; pPerson=ne
이걸 봐서는 그리 문제가 없어 보이는데...
SomeProcess() 등 함수 구현이 잘못된 거 아닐까요?
어찌나 졸린지..~~
생성자에서 memset(this, 0x00, sizeof(CChild))
생성자에서 memset(this, 0x00, sizeof(CChild)); 를 썼기 때문에 일어나는 현상이더군요.
_____________________________
언제나 맑고픈 샘이가...
http://purewell.biz
댓글 달기