c - 在 C 中,实现头文件的最低要求是什么?

标签 c header-files

我有一个这样开头的头文件:

typedef struct PriorityQueueStruct PriorityQueue;

/**
 * Type definition for an Element.
 */
typedef struct ElementStruct
{
    int element;
} Element;

/**
 * Type definition for a priority.
 */
typedef struct PriorityStruct
{
    int priority;
} Priority;

/**
 * Structure for containing the resultant values for a 
 *    call to 'createPriorityQueue'.
 *
 * 'token' is the identifier for the created data structure 
 *     and is to be used in any call to query or modify it.
 * 'resultCode' tells whether the function was successful or not in creating a 
 *     priority queue.  1 for success or an error code describing the failure.
 */
typedef struct InitializationResultStruct
{
        PriorityQueue* pq;
        int resultCode;
} InitializationResult;

/**
 * Structure for containing the resultant values for a 
 *    call to 'peek'.
 *
 * 'peekedValue' is the first-most value from the priority queue
 * 'resultCode' tells whether the function was successful or not in creating a 
 *     priority queue.  1 for success or an error code describing the failure.
 */
typedef struct PeekResultStruct
{
        Element element;
        Priority priority;
        int resultCode;
} PeekResult;

我对如何在我的简单类中实现这个头文件有点迷茫,它是一个优先级队列(称为 TriageQueue)的应用程序。我是否单独保留头文件中的结构?我该如何着手实现功能(感谢提示!)?感谢您的帮助!

最佳答案

C 没有类或方法。它有功能。

是的,假设您必须实现这个特定接口(interface),当然您需要单独保留声明。

虽然看起来有点不对劲,但注释引用的名称没有出现在声明中(tokenpeekedValue)。

关于c - 在 C 中,实现头文件的最低要求是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9467528/

相关文章:

c - 为什么 ...at syscall 使用与之前打开的不同的 dirfd?

c - open()系统调用头文件要求

c - C中的#import和#include有什么区别?

c - vsnprintf 等同于 Delphi?

c - 在 C(AVR 编程)中是否有一种简单的方法来选择变量应该存储在 RAM 还是 ROM 中并通过所有代码处理它?

c - 将字符串和字符传递给函数

c - 简单 C 代码中的错误(指针)

ios - 为什么 View Controller 的头文件中需要一个 Action 方法声明?

c++ - 使用头文件和源文件的模板化类

c - scanf() 调用后的指令被调用两次