[완료]함수포인터에 대한 질문입니다....

tommybee의 이미지

안녕하세요
그냥 데이터구조 공부하다가 에러가 생겨서 이렇게 질문 드립니다

다름이 아니라 제가 만든 것은 compare라는 함수 포인터를 활용하는 부분인데요 소스는 다음과 같이 하였습니다

t_linkedlist.h 파일이 아래와 같습니다.
typedef struct node
{
void* dataPtr;
struct node* link;
} NODE;

typedef struct
{
int count;
NODE* pos;
NODE* head;
NODE* rear;
int (*compare)(void*, void*);
} LIST;

LIST* createList (int (*compare)(void* argu1, void* argu2));

t_linkedlist.c 파일을 다음과 같이 작성하였습니다.
#include "t_linkedlist.h"

LIST* createList
(int (*comapre)(void* argu1, void* argu2))
{
LIST* __list;

__list = (LIST*)malloc(sizeof(LIST));

if(__list)
{
__list->head = NULL;
__list->pos = NULL;
__list->rear = NULL;
__list->count = 0;
__list->compare = compare;
} //end if

return __list;
}
그리고 linkedlist_main.c를 만들고 다음과 같이 작성 하였습니다

int cmpYear (void* pYear1, void* pYear2);

int main(int argc, int** argv)
{
LIST* list;

list = createList(cmpYear);
if(!list)
printf("\aCannot create list\n"),
exit(100);
return 0;
}

int cmpYear(void* pYear1, void* pYear2)
{
int result;
short year1;
short year2;

year1 = ((PICTURE*)pYear1)->year;
year2 = ((PICTURE*)pYear2)->year;

if(year1 result = -1;
else if( year1 > year2)
return 1;
else
result = 0;

return result;
}
에러메시지는 error C2065: 'compare' : undeclared identifier이구요
warning은 warning C4047: '=' : 'int (__cdecl *)(void *,void *)' differs in levels of indirection from 'int '입니다
물론 compare함수를 정의하지는 않았습니다만 나중에 메인에서 원래 int cmpYear (void* pYear1, void* pYear2);로 대체 할려고 했는 데요
이런 구문은 안되는 건가요? 고수님들의 조언 부탁드립니다
컴파일은 visual c++6.0에서 했습니다.

cppig1995의 이미지

1) C2065: createList 함수의 머리에 compare가 comapre로 적혀, 오타가 있습니다.
2) C4047: 몇 행에서 경고가 났는지 알려주시기 바랍니다.
3) pYear1이 정수 값 1987을 캐스팅한 것인 상황에서 year1 = ((PICTURE*)pYear1)->year;이라는 표현은 매우 위험하게 보여집니다.

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

tommybee의 이미지

오타군요.......
오타...
하지만 앞으로는 더 잘할 수 있을것 같습니다..