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

C++빌더 Q&A
C++Builder Programming Q&A
[71842] Re:c++ 런타임 오류 ㅠㅠ
Intotheblue [makerjh] 3447 읽음    2014-10-07 22:10
c/c++ 에서 배열은 0부터 시작합니다.

tan[5].set_name(1); 

는 없는 곳을 참조하고 있습니다.

정확한 문제 내용이 뭔지 모르겠으나..
배열을 쓰라고 해서 그걸 그대로.. tan[5] 바꿔 버리면..
출제 의도와는 맞지 않는 답일것 같네요.

허닝 님이 쓰신 글 :
: Run-Time Check Failure #2 - Stack around the variable 'tan' was corrupted.
: 라고 런타임오류가 뜨는데요 ... 객체를 배열로 선언해야하는게 문제풀이라서
:  main에서  van tan;를 van tan[5]; 이렇게 객체를 배열로 바꾸었는데 그 이후부터 런타임오류가떠요 객체 꼭 배열로 바꾸어야하는데..
: 어느 부분을 수정하면 될까요 ㅠㅠ !
:
: #include <iostream>
: using namespace std;

: int sum(int n, int m);
: short sum(short m, short n);

: struct my {
:  int b;
: };

: namespace A{
:  char sult[] = "a값을 입력하세요.";
:   void foo(void)
:  {cout << "플레이어 A:" << sult << endl;}
: }

: namespace B{
:  char sult[] = "c값을 입력하세요.";
:   void foo(void)
:  {cout << "플레이어 B:" << sult << endl;}
: }

: class van{
:  int d;
: public:
:  void set_name(int t) {d = t;}
:  int get_name() {return d;}
:  int get_side(van u)
:  {return u.get_name() + u.get_name();}
: };
:
: class String0 {
:     char *str;
: public:
:     void set_str(char *p);
:     void show_str();
: };
:
: void String0::set_str(char *p)
: {
:     str = p;
: }
:
: void String0::show_str()
: {
:     cout << "===" <<str << "===" << endl;
: }

: class String1{
:     char *strr;
: public:
:     void sett(char *i);
:     void showw();
: };
:
: void String1::sett(char *i)
: {
:     strr = new char;
: }
:
: void String1::showw()
: {
:     cout <<"-" << strr << "-" << endl;
:
: }
:
:
: String1 input_stre()
: {
:     char f[70];
:     String1 tmp;
:
:     cout << "게임을 시작합니다. y or n" << endl;
:     cin >> f;
:     tmp.sett(f);
:
:     return tmp;
: }
:
: int main(void)
: {
:  while(true){

:   my *number = new my;
:   van tan[5];
:   String1 ost;
:
:   ost = input_stre();

:   int a;
:   int c;

:   String0 s1, s2;
:
:   s1.set_str("(단, 1~5의 값이며 또 다른 수는 정해져 있습니다.)");
:   s2.set_str("(단, 1~5의 값이며 또 다른 수는 정해져 있습니다.)");
:
:   tan[5].set_name(1);
:   number -> b = 4;
:
:   int &o = a , &q = c;
:   //int i;

:   //for(i = 0; i<3; i++){
:
:   cout << endl;
:   s1 = s2;

:   A::foo();
:   s1.show_str();
:   cin >> a;

:   B::foo();
:   s2.show_str();
:   cin >> c;
:
:   double x = sum(o, number->b);
:   double y = sum(q, tan[5].get_side(tan[5]));

:
:   cout << "a + b의 값 :" << x << endl;
:   cout << "c + d의 값 :" << y << endl;

:   if(x == y){
:    cout << "소울메이트입니다. clear~!" << endl;
:    return 0;
:   }

:   else{
:    cout << "마음이 맞지 않군요. fail~!" << endl;
:   }
:   delete number;
:   //}
:  // return 0;
:  }
: }

: int sum (int n, int m)
: {
:  return n + m;
: }

: short sum (short m, short n)
: {
:  return n + m;
: }
:
:

+ -

관련 글 리스트
71841 c++ 런타임 오류 ㅠㅠ 허닝 3222 2014/10/07
71842     Re:c++ 런타임 오류 ㅠㅠ Intotheblue 3447 2014/10/07
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.