C 头文件给出错误 "VERTEX has no member ' p'"

标签 c struct header

我无法让这段代码工作。当它全部在一个文件中时它工作正常,但是当我将它拆分并放入头文件时,我得到了所有这些错误,例如(VERTEX 没有成员 p)和(VERTEX 没有成员 isVisited);奇怪的是,C 没有错误。我错过了什么?我做错了什么?

#ifndef MY_HEADER_INCLUDED
#define MY_HEADER_INCLUDED

struct EDGETAG;
struct LINKTAG;
//struct VERTTAG;

typedef struct
{
    char c;
    bool isVisited;
    EDGE* p;
} VERTEX;

typedef struct EDGETAG
{
    VERTEX* v;
    struct EDGETAG* q;
} EDGE;



typedef struct LINKTAG
{
    VERTEX* v;
    struct LINKTAG* next;
} VERTLINK;

int main(int argc, char *argv[]);
void bredthfirst(VERTLINK * start, int numVerts);
void depthfirst(VERTLINK * start, int numVerts);
void depthfirst(VERTLINK * start, int numVerts);
void showchart(VERTLINK * start, int numVerts);

#endif

这是包含 main 的文件中的一个简短示例,靠近底部是弹出错误的地方

#include "myheader.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int main(int argc, char *argv[])//(void)//
{
    FILE* fileAddress;
    int numVerts = 0;//0;
    int temper = 10;
    int * intArray;
    char templine[200];// = " ";//5];// = "  b";

    int getIndex = 0;
    int c = 0;
    int f = 0;
    int exitLoop = 0;
    bool vertfound = false;

    fileAddress = fopen(argv[1],"r");//

    int counter = 0;

    VERTLINK * currentlink;
    VERTLINK firstlink;
    VERTEX * tempvert;
    VERTEX * tempvertoo;
    EDGE * tempedge;
    EDGE * tempedgetoo;
    VERTLINK * templink;
    VERTLINK * templinktoo;
    while(fgets(templine, sizeof(templine), fileAddress) != NULL)
    {
        counter = 0;

         currentlink = &firstlink;

        while(templine[counter] == ' ')
        {
            counter++;
        }
        for(f = 0; f < numVerts; f++)
        {        
            if( (*(*currentlink).v).c == templine[counter])
            {
                vertfound = true;
                f = numVerts + 1;
            }
            else
            {
                if(f < numVerts - 1)// && numVerts != 6)
                {
                currentlink = (*currentlink).next;
                tempvert = (*currentlink).v;
                }


            }
        }
        if(vertfound)
        {vertfound = false;
        }
        else
        {
            if(numVerts == 0)
            {

                tempvert = malloc(sizeof (VERTEX));

                firstlink.v = tempvert;
                firstlink.next = NULL;
                (*firstlink.v).c = templine[counter];
                (*firstlink.v).isVisited = false;
                (*tempvert).p = NULL;

                numVerts++;
            }

这是编译器说的:

C:\...\CProject\finaldata\myheader.h|13|error: expected specifier-qualifier-list before 'bool'|
C:\...\CProject\finaldata\cgraph.c||In function 'main':|
C:\...\CProject\finaldata\cgraph.c|105|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|106|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|126|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|131|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|149|warning: comparison between pointer and integer|
C:\...\CProject\finaldata\cgraph.c|160|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|164|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|196|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|197|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|221|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|231|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|271|error: 'VERTEX' has no member named 'isVisited'|
C:\...\CProject\finaldata\cgraph.c|273|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|348|warning: implicit declaration of function 'topo'|
C:\...\CProject\finaldata\cgraph.c|361|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|362|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|388|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|390|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|391|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|414|error: 'VERTEX' has no member named 'p'|
C:\...\CProject\finaldata\cgraph.c|415|error: 'VERTEX' has no member named 'p'|
||=== Build finished: 20 errors, 2 warnings ===|

最佳答案

typedef struct
{
    char c;
    bool isVisited;
    struct EDGETAG* p;
} VERTEX;

关于C 头文件给出错误 "VERTEX has no member ' p'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20416206/

相关文章:

java - 获取原始 HTTP 响应 header

c - 使用 KV 存储管理 G-WAN 中的缓存

c - 在c中标记输入文件

c - 使用 pthread_barrier_wait 是否确保变量可见性?

c - 变量在第一次调用后发生变化 - C 中的未定义行为?

c - 增加结构成员

c - 包含两个双指针的结构体,访问第二个双指针时出现段错误

excel - 如何使用 apache POI 在 Excel 页面上设置标题?

c++ - Qt 方法返回没有完整对象定义的对象

C 结构填充。嵌套结构