Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[2424] Re:같은 코드인데 컴파일이 안되는군요
임문환 [mhlim] 1194 읽음    2003-04-18 17:12

오늘 VC++6.0 Enterprise를 구해서 컴파일해본 결과,
CPoly 클래스의 생성자에 있는 아래 코드를 지우고 하면 아무 오류 안나고 잘 되는데요.

if ( points != NULL ) // NULL이 아닌 경우 메모리 해제
  delete [] points;


빛살 님이 쓰신 글 :
: 조금 긴거지만 꼭 부탁드립니다....^^
:
: #include <iostream>
: using namespace std;
:
: class POINT //x,y의 좌표 설정 클래스
: {
:     public:
:         int x,y;
: };
:
: class CIntVector2 : public POINT // POINT를 상속받아 벡터형으로 표현
: {
:     public:
:         CIntVector2( int _x = 0, int _y = 0 ); //생성자
:         ~CIntVector2(); //소멸자
:         CIntVector2 operator +( const CIntVector2& intVector2 ); //+연산자 오버로딩
:         CIntVector2 operator -( const CIntVector2& intVector2 ); //-연산자 오버로딩
:         void operator()( int _x, int _y ); //()를 오버로딩
: };
:
: CIntVector2::CIntVector2( int _x, int _y )
: {
:     x = _x;
:     y = _y;
: }
:
: CIntVector2::~CIntVector2()
: {}
:
: CIntVector2 CIntVector2::operator +( const CIntVector2& intVector2 )
: {
:     return CIntVector2( x + intVector2.x, y + intVector2.y );
: }
:
: CIntVector2 CIntVector2::operator -( const CIntVector2& intVector2 )
: {
:     return CIntVector2( x - intVector2.x, y - intVector2.y );
: }
:
:
: void CIntVector2::operator()( int _x, int _y )
: {
:     x = _x;
:     y = _y;
: }
:
: class CPoly //다각형을 구현하기 위한 클래스
: {
:     public:
:         CIntVector2* points; //점들의 집합을 나타내는 포인터
:         int edge; //선분의 갯수
:    
:         CPoly();
:         CPoly( CIntVector2* _points, int _edge ); //배열과 선분의 갯수를 받는생성자
:         CPoly( const CPoly& _poly ); //복사생성자
:         ~CPoly();   
: };
:
: CPoly::CPoly() //디폴트 생성자
: {
:     points = NULL; //널로 설정
:     edge = 0; //0으로 설정
: }
:
: CPoly::CPoly( CIntVector2* _points, int _edge )
: {
:     edge = _edge; //선분 대입
:
:     if ( points != NULL ) // NULL이 아닌 경우 메모리 해제
:         delete [] points;
:    
:     points = new CIntVector2[edge]; //선분갯수 만큼의 동적할당
:
:     for ( int i = 0; i < edge; ++i ) { //인자로 받은 배열을 객체의 배열에 대입
:         (points+i)->x = (_points+i)->x;
:         (points+i)->y = (_points+i)->y;       
:     }
: }
:
: CPoly::CPoly( const CPoly& _poly )
: {
:     edge = _poly.edge;
:
:     if ( points != NULL )
:         delete [] points;
:    
:     points = new CIntVector2[edge];
:
:     for ( int i = 0; i < edge; ++i ) {
:         (points+i)->x = (_poly.points+i)->x;
:         (points+i)->y = (_poly.points+i)->y;       
:     }
: }
:
: CPoly::~CPoly() //소멸자
: {
:     if ( points != NULL )
:         delete [] points;
: }
:
: int main(int argc, char *argv[])
: {
:     CIntVector2 array[5]; //5개의 점을 생성
:     array[0](100,100); //각점들의 좌표 대입
:     array[1](200, 50);
:     array[2](300,100);
:     array[3](250,200);
:     array[4](150,200);
:      
:     CPoly poly1( array, 5 ); //좌표들을 가진 배열과 선분의 숫자 입력 <- 에러줄..ㅡ.ㅡ;;
:
:     for ( int i = 0; i < 5; ++i ) { // 시험삼아 객체에 있는 좌표들 출력
:         cout << poly1.points[i].x << " " << poly1.points[i].y << endl;
:     }   
:  
:   return 0;
: }
:
: dev-cpp와 빌더로 컴파일 하면 에러 없이 결과 값을 보여주는데
:
: 비쥬얼 C++로 하면 컴파일시는 에러가 없는데 실행동안에 메모리 참조 오류가
:
: 나는군요....
:
: 단지 컴파일러 문제인가요....아님 제가 잘못짠것인가요...
:
: 좋은 답변 부탁드립니다.

+ -

관련 글 리스트
2365 같은 코드인데 컴파일이 안되는군요 빛살 1264 2003/04/12
3994     Re:같은 코드인데 컴파일이 안되는군요 빛의화살 1270 2003/04/12
3993     Re:같은 코드인데 컴파일이 안되는군요 임문환 1219 2003/04/12
3992     Re:같은 코드인데 컴파일이 안되는군요 임문환 1275 2003/04/12
2424     Re:같은 코드인데 컴파일이 안되는군요 임문환 1194 2003/04/18
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.