오류의 원인을 못 찾겠습니다. [완료]

gauri123의 이미지

    prev_head_rrn = s[count].read_header(fp, count); // header 의 rrn을 읽어와 변수에 저장.
printf("prev_head_rrn : %d\n",prev_head_rrn); // Testing
    (void)s[count].write_header(fp, count); // 삭제할 레코드의 rrn을 header에 기록.

위의 read_header와 write_header를 호출하는 문에 주석을 씌우면 에러가 나지 않는데, 주석을 벗기고 테스트 해보려고 하면

정의되지 않음                   첫번째 참조된
 기호                       파일의
STUDENT::read_header(__FILE*, int&) /var/tmp//ccwecVFQ.o
STUDENT::write_header(__FILE*, int) /var/tmp//ccwecVFQ.o
ld: 치명적: 기호 참조 오류. a.out에 출력이 기록되지 않음
collect2: ld returned 1 exit status

라는 에러가 발생하네요... 해결법을 모르겠습니다.

아래는 함수 정의부 이구요.

int read_header(FILE *fp, int &rrn) {
FILE *copy_fp = 0 ;
int header;
static char tmp[4];
rrn = rrn;
copy_fp = fp;
fseek(copy_fp, 0,SEEK_SET);
fread(tmp, 4, 1, copy_fp);
header = atoi(tmp);
return header;
fclose(copy_fp);
}
 
int write_header(FILE *fp, int rrn) {
FILE *copy_fp = 0;
static char tmp[4];
 
copy_fp = fp;
sprintf(tmp,"%d",rrn);
fwrite(tmp,4,1,copy_fp);
fseek(copy_fp, 0, SEEK_SET);
fclose(copy_fp);
return 0;
}

아래는 헤더파일 내의 해당 함수 선언부입니다.
원래는 잘 작동되던 파일에 몇 부분을 추가한 것이라서 저 부분들중에 이유가 있는것 같네요...

그리고 함수 인자에 int &rrn 이게 뭔지 모르겠군요... 알려 주시면 정말 감사하겠습니다.

        int read_header(FILE *fp, int &rrn);    // header record에 있는 RRN값을 읽어 parameter 'rrn'에 저장한다.
        int write_header(FILE *fp, int rrn);    // parameter 'rrn'을 header record에 저장한다.
gauri123의 이미지

자문 자답입니다만, 해결했습니다.

소스에 read_header파일을 정의할때 STUDENT::read_header라고 적지 않고

read_header라고만 적어서 에러가 났습니다.

그러니 객체 밖에 동일명칭의 함수를 정의를 해놓고서는

객체 안에 아직 정의하지 않은 함수를 호출한 격이 되었네요.

객체지향언어를 써 본적이 없어 이런 실수가 나오네요.

타인을 자기 자신처럼 존경할수 있고, 자기가 하고 싶다고 생각하는 것을 타인에게 할 수 있다면, 그 사람은 참된 사랑을 알고 있는 사람이다. 그리고 세상에는 그 이상 가는 사람은 없다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.