C 访问函数返回的结构元素时遇到问题-取消对不完整类型的指针的引用

C 访问函数返回的结构元素时遇到问题-取消对不完整类型的指针的引用,c,pointers,struct,C,Pointers,Struct,我是C的新手。这是我正在处理的文件和代码。我试图调用一个函数(refineMatch),该函数是在主函数的一个单独文件中实现的。函数refineMatch返回一个结构。我在编译与访问返回结构中的元素相关的代码时遇到问题。编译错误发生在main.c文件中。下面的代码显示了错误发生的位置 精炼 #include <cv.h> #include <cxcore.h> #include <highgui.h> struct matchingpair{ CvP

我是C的新手。这是我正在处理的文件和代码。我试图调用一个函数(refineMatch),该函数是在主函数的一个单独文件中实现的。函数refineMatch返回一个结构。我在编译与访问返回结构中的元素相关的代码时遇到问题。编译错误发生在main.c文件中。下面的代码显示了错误发生的位置

精炼

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

struct matchingpair{
    CvPoint p1, p2;
};    

struct matchingpair_array{   
    struct matchingpair* elements;  
    int length;
};

struct matchingpair_array *refineMatch(struct matchingpair* pairs,int pointcount, int bestpair);
#包括
#包括
#包括
结构匹配对{
cvp点p1、p2;
};    
结构匹配对_数组{
结构匹配对*元素;
整数长度;
};
结构匹配对_数组*refineMatch(结构匹配对*pairs,int pointcount,int bestpair);
提炼

#include "refine.h"
#include "utils.h"
#include <stdlib.h>

struct matchingpair_array *refineMatch(struct matchingpair* pairs,int pointcount, int bestpoint){
    struct matchingpair_array refinedPairs;
    refinedPairs.elements=malloc(incount*sizeof(struct matchingpair));
    int *in=malloc(pointcount*sizeof(int)), i=0,incount=8;

    // several statements - including filling in[] with data

    for(i=0;i<incount;i++){ 
        refinedPairs.elements[i]=pairs[in[i]];
        fprintf(stderr,"%d\n",in[i]);
    }
    refinedPairs.length=incount;
    free(in); 
    // several other free() operations non include refinedPairs or elements
    return &refinedPairs;
}
#包括“refine.h”
#包括“utils.h”
#包括
结构匹配对\u数组*refineMatch(结构匹配对*pairs,int pointcount,int bestpoint){
结构匹配对(数组细化空气),;
definedPairs.elements=malloc(incount*sizeof(struct matchingpair));
int*in=malloc(pointcount*sizeof(int)),i=0,incount=8;
//多条语句-包括用数据填写[]
对于(i=0;ilength);//错误:取消对不完整类型的指针的引用
//其他代码
}
请给我解释一下我做错了什么。我正在使用gcc。
谢谢。

refineMatch()
不会返回结构。它返回指向结构匹配对数组的指针


matcingpair\u数组
mathingpair\u数组
不同:它缺少一个
h

试试“typedef struct…”哦!!谢谢你能解释一下为什么在那一点上它没有给我一个编译错误吗。当试图找到“matcingpair_数组”的匹配定义时,编译应该失败,不是吗?因为所有的定义都是指针。指向不完整类型的指针是可以的,直到您尝试取消引用它们(或应用于sizeof)。
#include "refine.h"
#include <stdio.h>

int main( int argc, char** argv ){
    struct matchingpair* pairs;
    int matchcount=0,bestpair;
    pairs=(struct matchingpair*)malloc(pairArrSize*sizeof(struct matchingpair));

    //values are assigned to pairs, matchcount and bestpair

    struct matcingpair_array* result=(struct matcingpair_array*)refineMatch(pairs,matchcount,bestpair); /*(casting removed this warining)
    warning: initialization from incompatible pointer type*/
    fprintf(stderr,"%d \n",result->length); //error: dereferencing pointer to incomplete type

    //some other code

}