2016-11-30 1 views
0

이전에 게시 한 동일한 문제의 답변을 찾으려고했지만 제대로 작동하지 않습니다. 내가 확인 한 링크 아래는 몇 :C 프로그래밍 : 매개 변수에 불완전한 형식 오류가 있습니다.

"parameter has incomplete type" warning C typedef: parameter has incomplete type How to resolve "parameter has incomplete type" error?

코드 :

:

여기
#include "listADT.h" 
#include "client.h" 
#include <stdlib.h> 
#include <stdio.h> 


struct node { 
    ClientInfo *data; // added pointer here 
    struct node * next; 
}; 

struct list_type { 
    struct node * front; 
    int size; 
}; 

ListType create() { 

    ListType listptr = malloc(sizeof(struct list_type)); 

    if (listptr != NULL) { 
     listptr->front = NULL; 
     listptr->size = 0; 
    } 
    return listptr; 
} 



void push(ListType listptr, ClientInfo item) { <--- error here 

    struct node *temp = malloc(sizeof(struct node)); 

    if (temp != NULL) { 
     temp->data = item; 
     temp->next = listptr->front; 
     listptr->front = temp; 
     (listptr->size)++; 
    } 
} 

int is_empty(ListType l) { 
    return l->size == 0; 
} 

int size_is(ListType l) { 
    return l->size; 
} 

void make_empty(ListType listptr) { 

    struct node* current = listptr->front; 

    while (current->next != NULL) { 
     destroy(listptr); 
     current = current->next;   
    } 

    (listptr->size)--; 

} 

void destroy(ListType listptr) { 
    struct node *temp = malloc(sizeof(struct node)); 
    temp = listptr->front; 
    listptr->front = listptr->front->next; 

    free(temp); 
    (listptr->size)--; 
} 

void delete(ListType listptr, ClientInfo item) { <--- error here 
    struct node* current = listptr->front; 
    struct node *temp = malloc(sizeof(struct node)); 

    while (current-> data != item) { 
     temp = current; 
     current = current->next;   
    } 

    temp->next = current->next; 
    (listptr->size)--; 
} 

int is_full(ListType l) { 

} 

이 구조체로 클라이언트가 다른 C 파일에 포함 된 내용입니다

typedef struct ClientInfo { 
    char id[5]; 
    char name[30]; 
    char email[30]; 
    char phoneNum[15]; 
} ClientInfo; 

그리고 내가 받고있는 오류는 다음과 같습니다.

listADT.c:41:40: error: parameter 2 (‘item’) has incomplete type 
void push(ListType listptr, ClientInfo item) { 
            ^
listADT.c:83:42: error: parameter 2 (‘item’) has incomplete type 
void delete(ListType listptr, ClientInfo item) { 

나는 그것을 고치는 방법에 관해서 정말로 분실했다. 포함해야 할 다른 정보가 있으면 알려주십시오.

편집 부분 |

listADT.h : ClientInfo itemClientInfo *item로 변경 후

#ifndef LISTADT_H 
#define LISTADT_H 

typedef struct list_type *ListType; 
typedef struct ClientInfo ClientInfo; 

ListType create(void); 
void destroy(ListType listP); 
void make_empty(ListType listP); 
int is_empty(ListType listP); 
int is_full(ListType listP); 
void push(ListType listP, ClientInfo item); 
void delete(ListType listP, ClientInfo item); 
void printl(ListType listP); 

#endif 

에러 :

listADT.h:12:6: note: expected ‘ClientInfo * {aka struct ClientInfo *}’ 
but argument is of type ‘ClientInfo {aka struct ClientInfo}’ 
void push(ListType listP, ClientInfo *item); 
+0

@kaylum은 게시하기 몇 초 전에 방금 추가했습니다. :) – Jasmine

+1

"다른 c 파일에 있습니다". 그게 효과가 없을거야. 직접 사용하거나 포함 된 헤더 파일에서 사용되는 모든 C 파일에서 정의해야합니다. – kaylum

+0

또는 매개 변수가 'ClientInfo * item'로 변경 될 수 있습니다. –

답변

2

타입 정의 구조체 클라이언트 정보를 클라이언트 정보;

이것은 순방향 선언입니다. 이는 나중에 client.c 파일에서 완료 될 불완전한 유형의 선언입니다. 그러나 헤더 파일에 전달 선언이있는이 디자인은 구조체의 내용을 비공개로 만듭니다.

프로그램의 다른 파일에는 구조체의 내용을 알 수 없으며 구성원에게 액세스 할 수도 없습니다. 그들에게는 구조체가 여전히 불완전 할 것이므로이 구조체 유형의 변수를 선언 할 수 없습니다. 그러나 구조체에 대한 포인터를 선언 할 수는 있습니다.

이것은 실제로 C에서 개체의 개인 캡슐화를 수행하는 방법입니다.이 개념은 "불투명 한 형식"이라고 불리며 좋은 OO 설계 방식으로 간주됩니다.

문제를 해결하기 위해 할 수있는 일은 "client.h"및 "client.c"의 모든 기능을 ClientInfo* 포인터 대신 사용할 수 있도록 변경하는 것입니다. 그런 다음 ClientInfo을 사용하는 모든 다른 파일은 포인터를 사용해야합니다. 그 유형의 객체를 선언 할 수 없기 때문에 생성자 (그리고 소멸자)를 제공해야합니다. 예 :

ClientInfo* client_create (void) 
{ 
    return malloc(sizeof(ClientInfo)); 
} 
관련 문제