【问题标题】:Functions with custom type in header标题中具有自定义类型的函数
【发布时间】:2016-04-14 19:26:13
【问题描述】:

我编写了一个程序,它使用三个函数,我将自定义类型传递给它们:

typedef struct w 
{
    char *wd;
    long position;
    struct w *next;
}W;
typedef W *word;

当我尝试将函数放在这样的头文件中时:

void find(char *s,word *T);
void seek(char *s,word p);
void look(word p);

并尝试编译我得到的文件

错误:未知类型名称“单词”

我该如何解决?

【问题讨论】:

  • 为什么?为什么你叫你的结构w????????这是什么意思?只是不要那样做,不要typedef指针。
  • 在使用前你需要有word的声明(至少)。
  • 请尝试创建一个Minimal, Complete, and Verifiable Example 并向我们展示。更具体地说,您的类型别名声明在哪里,与类型别名相关的函数原型在哪里?
  • 不要typedef指针!这会混淆代码,最终会导致以后的误解。

标签: c function types


【解决方案1】:

为什么不用这个?

typedef struct w
{
    char *wd;
    long position;
    struct w *next; 
}word;

#define word w

typedef struct w
{
    char *wd;
    long position;
    struct w *next; 
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 2021-09-07
    • 2018-10-04
    • 2017-07-18
    • 2018-11-03
    相关资源
    最近更新 更多